nginx 日志切割

新建文件 vi nginxLogRotate.sh

#!/bin/bash  

#Rotate the Nginx logs to prevent a single logfile from consuming too much disk space.   
LOGS_PATH=/usr/local/nginx/logs  
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)

赋予执行权限 chmod +x /usr/local/nginx/sbin/nginxLogRotate.sh

加入定时任务凌晨0点开始执行crontab -e

00 00 * * * /usr/local/nginx/sbin/nginxLogRotate.sh

按ESC :wq 回车键 保存

crond restart重启任务

阅读更多
文章标签: nginx log
个人分类: nginx
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭