What is the best way to rotate NGINX log files?

Hello Igor,

I have a question. What’s the best way to rotate the NGINX log file ? We
run NGINX as a Mail Proxy, and the log file grows quite large because we
don’t restart it very frequently.

Are there any alternatives to simply killing the NGINX process, zipping
up the error log, and then restarting NGINX ?

Regards,
Mansoor

There is no need to kill nginx. Use logrotate or something.

On Wed, Dec 05, 2007 at 10:41:30AM -0800, Mansoor P. wrote:

I have a question. What’s the best way to rotate the NGINX log file ? We run NGINX as a Mail Proxy, and the log file grows quite large because we don’t restart it very frequently.

Are there any alternatives to simply killing the NGINX process, zipping up the error log, and then restarting NGINX ?

Of course!

mv error.log error.log.0
kill -USR1 cat master.nginx.pid
wait 1 second and do anything with log

Thank you, Igor !

----- Igor S. [email protected] wrote:
| On Wed, Dec 05, 2007 at 10:41:30AM -0800, Mansoor P. wrote:
|
| > I have a question. What’s the best way to rotate the NGINX log file ? We run NGINX as a Mail Proxy, and the log file grows quite large because we don’t restart it very frequently.
| >
| > Are there any alternatives to simply killing the NGINX process, zipping up the error log, and then restarting NGINX ?
|
| Of course!
|
| mv error.log error.log.0
| kill -USR1 cat master.nginx.pid
| wait 1 second and do anything with log
|

Note that those steps can be handled by most syslog rotating programs by
specifying either the pid file (maybe with separate config file and
crontab entry), or by adding the kill line as a custom command in the
main rotation config file. :slight_smile:

For instance, on my OpenBSD systems, in newsyslog.conf after the ‘flags’
fields is the field for pif file, so…

logfile owner:group mode count size when flags

/…/access.log 644 9 512 * Z /…/nginx.pid

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs