保留过去30天的nginx日志

时间:2017-05-25 12:01:25

标签: nginx logging ubuntu-16.04

我想保留lsat的nginx日志30天。 默认配置为15天,如图所示。 enter image description here

我想保留最近30天。

以下是nginx的隐藏设置:

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

但它并没有说什么"怎么样?"应该采取。

我根本不是nginx专家,所以我不知道如何/在哪里可以更改该配置。

也许有人需要这样做,并希望帮助我。

2 个答案:

答案 0 :(得分:7)

要更改此行为,您必须更改nginx的logrotate文件。 该文件可能位于/etc/logrotate.d中。 要实现您尝试执行的操作,请将指令weeklyrotate 30放在与nginx对应的文件中。 之后,使用以下命令确保更改生效:

  • logrotate /etc/logrotate.d/nginx-config-file

答案 1 :(得分:3)

您可以为nginx设置logrotate,这样您就可以根据自己的要求维护30天或更长时间的日志!

/etc/logrotate.d/nginx


/var/log/nginx/access_log {
rotate 7
size 5k
dateext
dateformat -%Y-%m-%d
missingok
compress
sharedscripts
postrotate
    test -r /var/run/nginx.pid && kill -USR1 `cat /var/run/nginx.pid`
endscript
}

相应改变#rotate的值! 30,40等等...

相关问题