echo "57 23 * * * /usr/sbin/logrotate -f /etc/daily.logrotate.0/nginx >/dev/null 2>&1" >>/var/spool/cron/rootmkdir -p /etc/daily.logrotate.0/cat <<EOF>> /etc/daily.logrotate.0/nginx /var/log/nginx/*.log /var/log/nginx/json/*.log { daily #按天切割日志 missingok #忽略错误 rotate 15 compress #压缩文件 delaycompress #延迟一天压缩文件 dateext #以日期为单位 默认-%Y%m%d notifempty #空文件不切割 # create 0640 www-data adm #创建 0640权限的日志文件 create 644 sharedscripts #prerotate # if [ -d /etc/logrotate.d/httpd-prerotate ]; then # run-parts /etc/logrotate.d/httpd-prerotate; # fi #endscript postrotate if [ -f /run/nginx.pid ]; then kill -USR1 `cat /run/nginx.pid` #切割日志完成后通知nginx重新打开日志文件,不终止nginx fi endscript}