我正在运行Ubuntu15.04,并运行nginx
(apt-get install nginx
)的标准安装。
一切都运行得很好,但是我注意到nginx
日志正在旋转,但是nginx
继续输出到同一个日志文件,例如/var/log/nginx/error.log
是空的,而/var/log/nginx/error.log.1
正在将东西写到它。
当然,如果我重新启动nginx
,常规日志文件就会开始被写入。logrotate
脚本中有bug吗?是否需要在旋转时重新启动nginx
?
发布于 2015-05-28 14:24:25
nginx
写入旋转文件的原因是logrotate
文件中缺少一个postrotate
部分,以便nginx
重新加载nginx
的配置。
logrotate
已将文件重命名为or,但重命名不会关闭或更改文件描述符(内核内部维护一个描述符表,该表通过文件句柄或描述符演示所有打开的文件),文件句柄与以前一样。因此,nginx
进程将继续将文件句柄转储到同一个文件句柄(旋转的文件),而不是新创建的文件。
要解决此问题,请在postrotate
配置文件中添加一个logrotate
节,以重新加载nginx
的配置文件。
例如,下面是postrotate
部分的/etc/logrotate.d/apache2
:
postrotate
if /etc/init.d/apache2 status > /dev/null ; then \
/etc/init.d/apache2 reload > /dev/null; \
fi;
endscript
发布于 2020-02-15 10:28:44
创建一个文件/etc/logrotate.d/nginx,内容如下。至少对debian有帮助。你的里程可能会不同
/var/log/nginx/*.log {
daily
missingok
rotate 99
compress
delaycompress
notifempty
create 0640 www-data adm
sharedscripts
postrotate
/bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
endscript
}
https://askubuntu.com/questions/629375
复制相似问题