第一步:在nginx.conf里面把pid配置一下

第二步编写脚本:

/usr/local/nginx/sbin/cut_nginx_log.sh
#!/bin/bash 
# This script run at 00:00 
# The Nginx logs path 
 logs_path="/usr/local/nginx/logs/"
 logs_bak_path="/data/logs/nginx/"
 mkdir -p ${logs_bak_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
 cp ${logs_path}access.log ${logs_bak_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
 rm -rf ${logs_path}*.log
 kill -USR1 `cat /var/run/nginx.pid`

第三步加入到Crond里面

0 0 * * * *  sh /usr/local/nginx/sbin/cut_nginx_log.sh