配置文件
/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