Nginx日志按天进行切割

Nginx日志按天进行切割
先创建如下脚本:

/usr/local/nginx/sbin/nginxlogs.sh
#! /bin/bash
d=`date -d "-1 day" +%Y%m%d`

/bin/mv /usr/local/nginx/logs/access.log /usr/local/nginx/logs/nginx_access_$d.log

kill -USR1 `cat /usr/local/nginx/logs/nginx.pid` #让nginx重新生成日志

#/etc/init.d/nginx reload >/dev/null 2>/dev/null

再创建计划任务:

crontab -e
00 00 * * * /bin/bash /usr/local/nginx/sbin/nginxlogs.sh
#每天的0:00分执行此脚本