之前系统的nginx日志一致是自动切割的,突然某一天无法自动切割了,这样文件会特别大查询日志很不方便。
1、先用:sudo logrotate -f /etc/logrotate.d/nginx命令检查一下能不能切割,以及无法切割的原因
2、如果提示:error: skipping "/usr/local/nginx/logs/access.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.
这种很有可能是用非root权限的账号部署或者启动的nginx,这个时候就需要在/etc/logrotate.d/nginx种加入su root root。如下面的例子
/var/log/nginx/*.log { su root root daily missingok rotate 52 compress delaycompress notifempty create 0640 nginx root sharedscripts postrotate if [ -f /var/run/nginx.pid ]; then kill -USR1 `cat /var/run/nginx.pid` fi endscript }
浙公网安备 33010602011771号