Rotate Nginx logs in FreeBSD

The FreeBSD 10 base system includes the newsyslog utility which maintains log files to manageable sizes. E.g. after installing Nginx it’s good to setup log rotation for its log files. It can be done by adding the following line to /etc/newsyslog.conf:

/var/log/nginx-*.log 644 7 * @T00 GJ /var/run/nginx.pid 30

The first part of this line /var/log/nginx-*.log is the logfile name. We’re using glob pattern here.

Then file mode 644 is specified.

We’re keeping 7 log files and don’t trim them based on size (*).

The rotation is going to happen every night at midnight (@TOO).

Then we specify flags:

Nginx pid file is located /var/run/nginx.pid.

And USR1 signal (number 30) is sent during log rotation.

comments powered by Disqus