1.nginx_log_rotate.sh file
#nginx Log Cut script
#author: Henrylinux
#!/bin/bash
#1. set the log file storage directory, assuming that your Nginx The log exists in this directory
Logs_path= "/data/logs/nginx/"
#2. Set PID file, this according to your own environment, find Nginx.pid Location Directory
Pid_path= "/usr/local/nginx/logs/nginx.pid"
#3. Create a date file directory for split storage
Datetime= ' date-d "Yesterday" + "%y%m%d";
New_log_path= $logs _path$datetimemkdir-p $new _log_path
#4. move all log files in this directory by date
Log_file_list= ' ls-l $logs _path '; for log_file in $log _file_list;do
Log_file_name= $logs _path$log_file;
If [-f $log _file_name];
Then
MV $log _file_name $new _log_path;
Fidone
#5. to Nginx main process signal reopen log kill-usr1 ' Cat ${pid_path} '
2. Set up Scheduled Tasks
0 0 * * */data/sh/nginx_log_rotate.sh
Nginx Log Cutting