linux - Nginx被log-rotate杀死后如何重启?

标签 linux nginx logrotate

/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/

相关文章:

docker - 无法将 flask Web与容器中的Nginx连接

nginx - 回退到 nginx 中的默认/共享文件

linux - 使用 copytruncate 时如何在 perl 中跟踪文件

linux - Grep 带空格的单词

php - 如何从命令终端获取网络流量并在 PHP 中显示

Linux .profile 覆盖其他 bash 命令

php - 使用 PHP set_time_limit() 防止 nginx 504 网关超时

python - 删除文件时检测python中的中断流

java - 在java中写入日志文件是通过文件名还是其他东西(如 inode 、文件句柄等)来跟踪的?

python - 从脚本创建和构建 docker Dockerfile