记录生活的点点滴滴~~~

Debian上使用logrotate分割管理Nginx日志

以前nginx需要写脚本来分割日志,最近发现debian服务器下的logrotate可以用来分割日志,功能比自己写脚本强多了

效果如图

新建/etc/logrotate.d/nginx,输入内容

/var/log/nginx/access.log {
  daily  每天分割一次
  dateext 分割后日志标题带有时间
  dateformat %Y%m%d 设置时间格式为年月日
  extension .log 日志文件以.log结尾
  rotate 60 保存60天的日志
  #compress 压缩
  #delaycompress 
  notifempty
  create 0640 www-data www-data 创建日志的用户、用户组
  sharedscripts
  prerotate
      if [ -d /etc/logrotate.d/httpd-prerotate ]; then 
          run-parts /etc/logrotate.d/httpd-prerotate; 
      fi 
  endscript
  postrotate
      [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
  endscript
}
Debian上使用logrotate分割管理Nginx日志

https://geekyotter.com/posts/using-logrotate-to-split-and-manage-nginx-logs-on-debian.html

作者

超级水獭

发布时间

2013-07-16

许可协议

无,保留所有权利

本页的评论功能已关闭