在 /etc/logrotate.d/nginx
我发现:
/var/log/nginx/*.log {
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 640 nginx adm
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}
我很好奇的是 postrotate
命令。
我认为这意味着一旦日志成功轮转,它就会终止 nginx 进程。
我知道在重新启动 nginx 时会创建新日志。
我想不通的是,进程是如何自动重启的,是否中断了网页服务?
最佳答案
logrotate
作为每日 cron 作业运行将重命名 /var/log/nginx/*.log
中的日志文件。
之后nginx就不能输出error log和access log到原始日志文件了。 (有关更多详细信息,请参阅此答案下@mata 的评论。)
要解决这个问题,应该向nginx 发送USR1
信号以重新打开日志文件。
这就是为什么 postrotate
发送 USR1
给 nginx master,这个信号不是要杀死 nginx。
有关使用信号控制 nginx 的更多详细信息,请参阅 this document .
关于linux - Nginx被log-rotate杀死后如何重启?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36325214/