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
List DNS records, nameservers of a domain from command line
Viewed 457 times since Sun, Sep 30, 2018
Split and Reassemble files
Viewed 913 times since Mon, May 28, 2018
RHEL: What is "SysRq key" and how to use it
Viewed 1286 times since Sat, Jun 2, 2018
Learn how to align an SSD on Linux
Viewed 106 times since Fri, May 15, 2020
Applescript: Run or Call a Shell Script
Viewed 581 times since Tue, Aug 6, 2019
How to do a Filesystem Resize (ext3/ext4) on Redhat running on VMware
Viewed 1186 times since Wed, Jul 25, 2018
Fake A Hollywood Hacker Screen in Linux Terminal linux FUN
Viewed 559 times since Thu, Apr 18, 2019
RHCS6: Install a two-node basic cluster
Viewed 706 times since Sun, Jun 3, 2018
LVM: Extend SWAP size by growing existing Logical Volume
Viewed 678 times since Sat, Jun 2, 2018
SSH ProxyCommand example: Going through one host to reach another server
Viewed 1389 times since Tue, Aug 6, 2019