Nginx log cutting script

  
 

Apache itself has the ability to automatically cut log files, and Nginx itself can't split logs by day. It needs to be automatically split by script.

Split the log through the shell script +crontab:

#vi cut_nginx_access.log

#!/bin/bashlogs_path=”/opt/nginx-h264/logs” #######This is the directory where my nginx log file is located date=$(date -d “yesterday” +”%Y-%m-%d”) #######前前The time of day, the format is year-month-day mv ${logs_path}/access.log ${logs_path}/access_$date.log ###### Rename the log file kill -USR1 `cat /with yesterday's date Opt/nginx-h264/logs/nginx.pid` #######Regenerate log files

#crontab -e

00 00 * * * sh /opt/cut_nginx_access. Log#service crond restart

Copyright © Windows knowledge All Rights Reserved