Linux nginx log split by day instance
Nginx Log has a small disadvantage, the log file has always been one, will not be automatically cut, if the traffic is very large, will cause the log file is very large, not easy to manage
That's what we need to do. Produce one log file per day by date
Ideas
Rename the default log file to today's date at 0 o ' Day and reopen the new log file
Use timed tasks to execute scripts, rename and reopen log files in scripts
You can reopen the log file by sending a USR1 signal to the Nginx main process
Realize
#/bin/bash
#备份日志的路径
Bakpath= '/home/nginx/logs '
#nginx日志路径
Logpath= '/usr/local/nginx/logs '
#在备份路径下创建年月子目录
Mkdir-p $bakpath/$ (date +%y)/$ (date +%m)
#移动日志文件到备份路径, and renamed to date format
MV $logpath/access.log $bakpath/$ (date +%y)/$ (date +%m)/access.$ (date +%y%m%d). log
MV $logpath/error.log $bakpath/$ (date +%y)/$ (date +%m)/error.$ (date +%y%m%d). log
#用 USR1 signal let nginx reopen log file
KILL-USR1 ' Cat/usr/local/nginx/logs/nginx.pid '
Linux nginx log split by day instance