以前我只做日志文件,
access_log /var/log/nginx/infotrack_access.log rsyslog;
我将下面的文件添加到我的/etc/nginx/sites-available/alpha.conf文件中,
access_log syslog:server=localhost:514,tag=infotrack rsyslog;
在我添加这行后,我遇到的问题是文件infotrack_access.log而不是文件infotrack_access.log.1 。
这里是/etc/logrotate.d/nginx文件,
/var/log/nginx/*.log { daily missingok rotate 14 compress delaycompress notifempty create 0640 www-data adm sharedscripts prerotate if [ -d /etc/logrotate.d/httpd-prerotate ]; then \ run-parts /etc/logrotate.d/httpd-prerotate; \ fi \ endscript postrotate invoke-rc.d nginx rotate >/dev/null 2>&1 endscript }
当我重新加载或重新启动nginx时,一会儿日志logging到innfotrack_access.log ,但过了一会儿,日志再次进入infotrack_access.log.1
为什么发生这种情况? 我在/etc/nginx/nginx.conf文件中没有做任何修改。
我如何解决它?
在debugging和强制模式下运行logroate。 logrotate --force -d /etc/logrotate.d/nginx 。 这将会显示详细的错误信息。 同时检查日志文件夹的所有者。
这可能与这个bug有关: https : //bugs.launchpad.net/nginx/+bug/1450770
在Tux_DEV_NULL发布的错误链接中得到了答案。
看起来像nginx旋转后面临一些问题。
所以,我需要对postrotate部分进行一些修改,
postrotate #invoke-rc.d nginx rotate >/dev/null 2>&1 start-stop-daemon --stop --signal USR1 --quiet --pidfile /run/nginx.pid --name nginx endscript
或者对于一些,这也适用,
postrotate #invoke-rc.d nginx rotate >/dev/null 2>&1 nginx -s reload endscript