1、創建腳本/usr/local/nginx/sbin/cut_nginx_log.sh
vi /usr/local/nginx/sbin/cut_nginx_log.sh
輸入以下內容:
#!/bin/bash
# This script run at 00:00# The Nginx logs path
logs_path=”/home/www/logs/”mkdir -p ${logs_path}$(date -d “yesterday” +”%Y”)/$(date -d “yesterday” +”%m”)/
mv ${logs_path}access.log ${logs_path}$(date -d “yesterday” +”%Y”)/$(date -d “yesterday” +”%m”)/access_$(date -d “yesterday” +”%Y%m%d”).log
kill -USR1 `cat /usr/local/nginx/nginx.pid`
2、設置crontab,每天凌晨00:00切割nginx訪問日志
crontab -e
輸入以下內容:
00 00 * * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh