In linux, we can use crontab to regularly move access. log to the backup directory. at the same time, we can signal USR1 to the nginx main process to generate a new log file. Before writing the script, make the following assumptions: the log file is/usr/local/nginx/logs/access ....
In linux, we can use crontab to regularly move access. log to the backup directory. at the same time, we can signal USR1 to the nginx main process to generate a new log file.
Before writing a script, perform the following assumptions:
The log file is/usr/local/nginx/logs/access. log.
The nginx master process id is saved in the file:/usr/local/nginx/logs/nginx. pid
Directory of the backup file after cutting:/usr/local/nginx/logs/bak/
For detailed steps of cutting, see the following operations:
1. create the file cut_access_log.sh:
Vim/. bin/cut_access_log.sh
2. input file cut_access_log.sh content
#! /Bin/bash
Org_path = "/usr/local/nginx/logs /"
Dest_path = "/usr/local/nginx/logs/bak /"
If [! -D "$ dest_path"]; then
Mkdir "$ dest_path"
Fi
Mv $ {org_path} access. log $ {dest_path} access $ (date + % Y % m % d). log
Kill-USR1 'cat/usr/local/nginx/logs/nginx. pid'
3. after saving cut_access_log.sh, grant the executable permission
Chmod + x/. bin/cut_access_log.sh
4. Compile the crontab file:
Vim/. cron
5. enter the content of the crontab file and keep it
59 23 ***/bin/bash/. bin/cut_access_log.sh
6. add to crontab
Crontab/. cron
In the preceding six steps, if you have sufficient permissions, access logs are cut at every day.
From the blog of the pure soul