基本centos7 系统已自带logrotate,其他系统并未测试

#新建nginx 日志任务

vi /etc/logrotate.d/nginx

/usr/local/nginx/logs/access.log  {
daily
rotate 7
missingok
dateext
nocompress
delaycompress
notifempty
sharedscripts
postrotate
    [ -e /usr/local/nginx/logs/nginx.pid ] && kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
endscript
}

#启动任务

logrotate /etc/logrotate.d/nginx

#强制手动执行,是否可以生成日志文件

logrotate -vf /etc/logrotate.d/nginx

#新建定时任务,每天 23:55执行一次

crontab -e

55 23 * * * /usr/sbin/logrotate -vf /etc/logrotate.d/nginx

退出保存