Limit NGINX Access Log File Size and Enable Compression

gziploggingnginxUbuntu

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?

Best Answer

/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
}
Related Topic