nginx日志切割脚本

nginx_log.sh
最后记得添加定时任务

#nginx日志切割脚本
#author: http://www.nginx.cn/255.html
 
#!/bin/bash
#设置日志文件存放目录
logs_path="/home/wwwlogs/"
#设置pid文件
pid_path="/usr/local/nginx/logs/nginx.pid"
 
#重命名日志文件
mv ${logs_path}meikuxiu.com.log ${logs_path}meikuxiu.com_$(date -d "yesterday" +"%Y%m%d").log
 
#向nginx主进程发信号重新打开日志
kill -USR1 `cat ${pid_path}`
 
 
#crontab 设置作业
#0 0 * * * bash /usr/local/nginx/nginx_log.sh

Leave a Reply

Your email address will not be published.