Overview
Set log rotation with Cronolog.
Environment
- OS
- Linux www4322gi 3.2.0-64-generic #97-Ubuntu SMP Wed Jun 4 22:04:21 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Work flow
1.Check log setting of Nginx
If you change the setting, do not forget to restart.
sudo vim /etc/nginx/sites-available/main
-----
access_log /home/www/logs/access.log;
error_log /home/www/logs/error.log;
-----
sudo /etc/init.d/nginx restart
2.Install Cronolog
sudo apt-get install cronolog
3. Remake log files
rm /home/www/logs/access.log
rm /home/www/logs/error.log
mkfifo /home/www/logs/access.log
mkfifo /home/www/logs/error.log
4. Setting of Cronolog
tail -f /home/www/logs/access.log | /usr/bin/cronolog /home/www/logs/access.%Y-%m-%d.log
tail -f /home/www/logs/error.log | /usr/bin/cronolog /home/www/logs/error.%Y-%m-%d.log
Reference