Apache日志访问已经旋转的日志文件

我通常在/var/log下的域名文件夹中创build我的访问和错误/var/log ,并使用此conf将这些文件与logrotate一起旋转:

 /var/log/mydomain.org/access.log { weekly missingok rotate 52 compress delaycompress notifempty create 640 root adm sharedscripts prerotate /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mydomain.org &> /dev/null endscript postrotate if [ -f /var/run/apache2.pid ]; then /etc/init.d/apache2 restart > /dev/null fi endscript } 

我经常access.log这个问题:我的access.log被转到access.log.1 ,但是apache2保持对access.log.1日志访问。

我无法弄清楚为什么会发生这种情况。 任何帮助?

提前致谢。

我会猜测你是apache进程没有在“/var/run/apache2.pid”中放置一个pid文件,因此你的postrotate永远不会执行。 在排除故障时(正如faker的评论所暗示的那样)

...
postrotate
/etc/init.d/apache2 restart > /tmp/apache_restart.txt
endscript
}

那么明天再看看/tmp/apache_restart.txt和more /tmp/apache_restart.txt

为什么你会使用logrotate来旋转apache日志,当你可以在一个简单的指令?

你可以使用像这样的东西:

 ErrorLog "|/usr/sbin/rotatelogs /var/logs/httpd/error_log 86400" 

这样你就不需要处理文件上的锁,而且apache会为你转动日志。