nginx 主机服务器日志轮换所有站点

nginx 主机服务器日志轮换所有站点

我在目录中为每个网站设置了单独的日志文件

/var/log/nginx-hosts/

我必须为这些文件配置日志轮换。我首先要使用的基础是

/var/log/nginx-hosts/*.log {
    rotate 7
    daily
    missingok
    notifempty
    sharedscripts
    copytruncate
    compress
}

但是,就像 apache 一样,nginx 似乎必须关闭预旋转才能真正截断它们。当前的 nginx logrotate 配置为:

/var/log/nginx/*.log {
        daily
        missingok
        rotate 52
        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
                [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
        endscript
}

我应该将单个站点日志轮换纳入主要站点还是努力找出不同文件中的第一个配置。有什么想法吗?有什么主意吗?

谢谢您的帮助,祝您节日快乐。

答案1

进一步挖掘后,我找到了以下解决这个问题的方法:

/var/log/nginx-hosts/*.access{
        weekly
        missingok
        rotate 20
        compress
        dateext
        notifempty
        create 0640 www-data adm
        sharedscripts
        sharedscripts
        prerotate
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi; \
        endscript
        postrotate
                [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
        endscript
}
/var/log/nginx-hosts/*.error{
        weekly
        missingok
        rotate 20
        compress
        dateext
        notifempty
        create 0640 www-data adm
        sharedscripts
        sharedscripts
        prerotate
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi; \
        endscript
        postrotate
                [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
        endscript
}

相关内容