nginx脚本设置,每天一个新文件
1.nginx截取脚本
将该脚本放到/script文件目录下:
#!/bin/bash
# 每天一个日志文件
LOGS_PATH=/var/log/nginx
# pid路径
PID=/usr/local/nginx/logs/nginx.pid
# time
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
mv ${LOGS_PATH}/access.log ${LOGS_PATH}/access_${YESTERDAY}.log
mv ${LOGS_PATH}/error.log ${LOGS_PATH}/error_${YESTERDAY}.log
## 向 Nginx 主进程发送 USR1 信号。USR1 信号是重新打开日志文件
#kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)
kill -USR1 `cat ${PID}`
2.设置定时任务
# crontab -e
# 输入以下内容并保存script
00 00 * * * /bin/bash /script/cut_nginx_log.sh
网友评论