Log rotation

Igor Sysoev is at rambler-co.ru
Wed Sep 20 02:49:17 MSD 2006


On Tue, 19 Sep 2006, Bob Ippolito wrote:

> It looks like nginx can do log rotation by sending it USR1, but I
> haven't seen any English mention of this outside of the source code.
> Could someone show an example of how log rotation works with nginx? Is
> there a recommended log rotation tool that can handle this style of
> log rotation? I've been using piped log processes (mostly rotatelogs)
> w/ Apache for years to handle this issue.
>
> Currently most of my nginx usage is as a proxy, so I've just turned
> access logs off.. but I would like to replace Apache in a few other
> places, so I need to have rotated logs.

When master process receives -USR1 it repopens all logs, does chown()
and chmod() (to allow unpriviliged worker processes to reopen them),
and notifies workers about reopening. Then the workers reopens its
logs too. So the old logs are available to gzip right away - you will
not lose any line. The sequence is following:

mv access_log  access_log.0
mv error_log  error_log.0
kill -USR1 master
sleep 1
gzip access_log.0
gzip error_log.0

nginx does not support piping logs.


Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list