nginx 日志定时任务切割logrotate

时间:2020-02-16 10:22:21   收藏:0   阅读:64

配置文件

/alidata/log/nginx/aipiaxi/*.log
{
  daily
  rotate 15
  missingok
  dateext
  compress
  notifempty
  sharedscripts
  postrotate
    if [ -f /var/run/nginx.pid ]; then
      kill -USR1 `cat /var/run/nginx.pid`
    fi
  endscript
}

 

最后脚本的意思是,让nginx日志开始一个新的日志文件。

 

然后添加定时任务

crontab -e

0 4 * * * /usr/sbin/logrotate -vf /etc/logrotate.d/nginx

每天凌晨4点切割日志

 

日志格式

 

nginx.conf

log_format main [$time_iso8601] "$http_x_forwarded_for" "$request" 
                      $status $body_bytes_sent "$http_referer" 
                      "$http_user_agent" ;

# 使用 access_log /path/to/log main;

 

原文:https://www.cnblogs.com/aleafo/p/12315530.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!