Source: https://www.centos.bz/2011/03/split-nginx-logfile-eveyday/
Nginx generated by the log is a file, with the longer the website running time, the size of the log file is also growing, which we want to analyze the day log is very inconvenient, so we need to split the log file every day, and named after the time.
Create a log split script
1. Login to SSH, create cut_logs.sh file
vi/root/cut_logs.sh
2. Paste the following code into cut_logs.sh, and save
#!/bin/bash# the Nginx logs pathlogs_path= "/home/wwwlogs/" Mkdir-p ${logs_path}$ (date-d "Yesterday" + "%Y")/$ (date-d "Ye Sterday "+"%m ")/mv ${logs_path}www.juzihc.com.log ${logs_path}$ (date-d" Yesterday "+"%Y ")/$ (date-d" Yesterday "+"%m ") /juzihc_$ (date-d "Yesterday" + "%y%m%d"). LOGKILL-USR1 $ (cat/usr/local/nginx/logs/nginx.pid)
3. Add cut_logs.sh Execute Permissions
chmod +x/root/cut_logs.sh
Set cut_logs.sh start time
Execute command crontab-e enter edit state
Add the following code, which starts every day 0:01.
* * * */root/cut_logs.sh
This makes it successful to split the log files on a daily schedule. Of course, if you're worried about the log file taking up too much space, you can also perform a compressed tar and set the log file to delete many days ago.
For more information about operations and maintenance, refer to:
https://www.centos.bz/
such as: Zabbix monitoring memcached php-fpm Tomcat Nginx MySQL website Log
Automatically split nginx log files every day