Logrotate Example for Custom Logs

Logrotate Example for Custom Logs

You will need this if you are using custom location for log files.

Below is example for Nginx where log files are directly created in /var/www/example.com/logs

You can put following in /etc/logrotate.d/nginx

/var/www/example.com/logs/*.log {
        rotate 52
        create 0640 www-data adm
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi; \
                [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`


Its always better to verify if logrotate script is correct.

Just run command

logrotate -d

It will produce debug output.

Restart/Force Update

Remember, logrotate is not service which can be restarted. In case you need your logrotate script to run immediately, use:

logrotate -f -v /etc/logrotate.d/nginx

Rotating log is very important. Otherwise some day your harddisk may get full and then mysql will be the first process which will refuse to start!

0 (0)
Article Rating (No Votes)
Rate this article
There are no attachments for this article.
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
How to Migrate from RHEL 8 to CentOS 8
Viewed 1063 times since Fri, May 15, 2020
12 Linux Rsync Options in Linux Explained
Viewed 9685 times since Wed, Oct 31, 2018
Viewed 1133 times since Fri, Jul 27, 2018
RHCS: Install a two-node basic cluster
Viewed 7823 times since Sun, Jun 3, 2018
Testing TLS/SSL encryption
Viewed 11184 times since Thu, Jan 16, 2020
RHEL: Services basic management - chkconfig
Viewed 3666 times since Sat, Jun 2, 2018
RHEL: Checking HBAs
Viewed 11017 times since Sun, May 27, 2018
systemd Auto-restart a crashed service in systemd
Viewed 1087 times since Fri, Jan 17, 2020
Df command in Linux not updating actual diskspace, wrong data
Viewed 1380 times since Wed, May 30, 2018
How to stop and disable auditd on RHEL 7
Viewed 24176 times since Tue, Aug 6, 2019