I wrote this article before.ArticleHowever, this log is missing due to the previous data loss fault. So I re-wrote this script and posted it again to everyone.
#! /Bin/bashlogs_path =/home/logs/www/arch_log_path =$ {logs_path} $ (date-d "yesterday" + "% Y % m/% d ") /mkdir-p $ {arch_log_path} CD $ {logs_path} For I in 'ls *. access. log 'do tar zcf logs into iw..tar.gz-C $ {logs_path }$ {I} MV logs into I =.tar.gz $ {arch_log_path} Rm-RF $ {I} donekill-usr1 'cat/usr/local/nginx /nginx. PID'
Modify the logs_path to your nginx access log directory. My nginx displays access logs by virtual host. The format of each log file is as follows: localhost. access. log, the script will match all * in the log directory *. access. log file, which is compressed and moved to the directory of the year, month, and day. You can make adjustments as needed. After the setting is successful, add the scheduled task to the crontab.
Sudo crontab-e
Start the VI editor and enter the following content:
0 0 ***/path/to/cut_nginx_log.sh
Change the last part to the path where your cutting script is located. The timer is set to archive logs of the previous day at every day.