参考张宴博客:http://blog.s135.com/nginx_php_v6/  做了下修改

1、创建脚本 cut_nginx_log.sh

#!/bin/sh
# This script run at 00:00

# The Nginx logs path
logs_path="/usr/local/nginx/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/logs/nginx.pid`

2、设置crontab,每天凌晨00:00切割nginx访问日志
 

crontab -e

内容如下:

00 00 * * * sh  /usr/local/nginx/cut_nginx_log.sh
 
3、测试:运行
转移的log如下
[root@~ logs]# ll 2011/08/access_20110808.log
-rw-r--r-- 1 www root 0 Aug  9 10:18 2011/08/access_20110808.log