20

I'm hoping to get some direction on how to set up truncating and gzip'ing on my domains' access logs. I notice that the core nginx access logs get split and compressed by default, yet my individual access logs continue to grow.

Is this something that can be set up and is handled by nginx or something else on my system that is managing it's core logs?

2
  • Use logrotate? Sep 13, 2012 at 15:34
  • Here's a good detailed post about using logrotate for nginx
    – ABS
    Jan 20, 2021 at 7:26

1 Answer 1

36

/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
}
6
  • 1
    Awesome. Logrotate was new to me. Makes perfect sense now. Thanks!
    – Draculater
    Sep 13, 2012 at 15:41
  • man logrotate for additional details.
    – Seth
    Apr 3, 2017 at 18:31
  • 1
    I had to do the following to make it start with new config: sudo logrotate -v -f /etc/logrotate.d/nginx
    – talsibony
    Mar 22, 2018 at 10:54
  • 3
    The command that actually rotates the logs is "kill -USR1 /var/run/nginx.pid". This does not kill the Nginx process, but instead sends it a signal causing it to reload its log files. This will cause new requests to be logged to the refreshed log file. Source Aug 9, 2018 at 14:30
  • 1
    Could somebody explain what these are and what this is doing?
    – Esqarrouth
    Apr 3, 2019 at 22:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .