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
LVM: Reduce an existing Volume Group by removing one of its disks
Viewed 866 times since Sat, Jun 2, 2018
Linux - How to get CPU information
Viewed 694 times since Fri, Jun 8, 2018
CentOS / RHEL 7 : Configuring an NFS server and NFS client Linux NFS
Viewed 3747 times since Fri, Feb 21, 2020
Top 4 Reasons for Node Reboot or Node Eviction in Real Application Cluster (RAC) Environment
Viewed 10679 times since Thu, Jun 21, 2018
7 Tips – Tuning Command Line History in Bash
Viewed 1662 times since Fri, Jul 5, 2019
12 Tcpdump Commands – A Network Sniffer Tool
Viewed 817 times since Fri, Jul 27, 2018
LVM: Reduce SWAP size by shrinking existing Logical Volume
Viewed 1158 times since Sat, Jun 2, 2018
Using stunnel to Encrypt Database Connections
Viewed 1475 times since Fri, Sep 28, 2018
YUM CRON RHEL7: Configure automatic updates.
Viewed 621 times since Fri, Oct 26, 2018
Find All Large Files On A Linux System
Viewed 810 times since Mon, Oct 29, 2018