How to limit nginx access log file size and compress?
29,460
/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 videos on Youtube
Author by
Draculater
Updated on September 18, 2022Comments
-
Draculater over 1 year
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?
-
Michael Hampton over 11 yearsUse
logrotate
? -
ABS over 3 yearsHere's a good detailed post about using logrotate for nginx
-
-
Draculater over 11 yearsAwesome. Logrotate was new to me. Makes perfect sense now. Thanks!
-
Seth about 7 years
man logrotate
for additional details. -
talsibony about 6 yearsI had to do the following to make it start with new config:
sudo logrotate -v -f /etc/logrotate.d/nginx
-
Edson Horacio Junior almost 6 yearsThe 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
-
Esqarrouth about 5 yearsCould somebody explain what these are and what this is doing?
-
Darko Maksimovic about 5 yearsFrom man page: "Normally, logrotate is run as a daily cron job". It doesn't require running it with -v or -f etc. like in talsibony's comment. More details in unix.stackexchange.com/questions/116136/…