美文网首页
nginx日志自动按天切割

nginx日志自动按天切割

作者: 南岩飞雪 | 来源:发表于2019-03-26 20:21 被阅读0次

来源

同事

nginx的access.log,error.log自动按天切割

nginx 1.16版本开始自带了日志切割功能,而1.12版本,目前有几种办法可以做到按天切割

  • 第一种方法:通过shell脚本+crontab定时任务自动扫描
  • 第二种方法:通过linux自带的logrotate实现

编辑 /etc/logrotate.d/nginx 文件,内容替换为下面内容(含义是:日志按天分割,最多保留15份,10m以下的不处理,执行完了分割以后reload nginx,防止日志不写到新的文件中)

/home/admin/logs/nginx/*.log{
      daily
      rotate 15
      minsize 10M
      sharedscripts
      postrotate
             sudo service nginx reload>/dev/null 2>&1
      endscript
}

然后执行sudo /usr/sbin/logrotate /etc/logrotate.conf 重新加载

相关文章

网友评论

      本文标题:nginx日志自动按天切割

      本文链接:https://www.haomeiwen.com/subject/waonvqtx.html