TECHIES WORLD

For Techs.... Techniques.... Technologies....

BashLinux

How to configure log rotation for Nginx using logrotate

This article explains the steps to configure log rotation for Nginx using logrotate.

Step1: Login to the server via ssh as root.

Step2: Change the location to logrotate configuration folder.

#cd /etc/logrotate.d

Step3: Create the configuration for Nginx log rotation.

#vi nginx.conf

Step4: Update the following files to the new file and save.

/var/log/nginx/*.log {
daily
rotate 5
compress
delaycompress
postrotate
/bin/systemctl reload nginx > /dev/null 2>/dev/null || true
endscript
}

Step5: Dry run the logrotate to check if any issues.

#logrotate -d /etc/logrotate.d/nginx.conf

That's all…