vim /etc/logrotate.d/nginx
/usr/local/nginx/logs/*.log { daily size 10m minsize 10m rotate 30 missingok notifempty compress nodelaycompress copytruncate dateext dateformat -%Y-%m-%d dateyesterday postrotate if [ -f /usr/local/nginx/logs/nginx.pid ];then kill -USR1 `cat /usr/local/nginx/logs/nginx.pid` fi endscript }
配置说明:
因为系统默认的logrotate规则比较奇葩,所以直接删了默认规则,自行定义。
rm -rf /etc/cron.daily/logrotate
crontab -e
新建crontab规则:00 00 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx
,这样每天凌晨0点0分就会执行nginx日志切割。注意确认logrotate命令的位置。