标签:centos 发送 error Oday cut today 自身 pat nginx log
Nginx自身是没有按日期切割日志的功能,可以用shell脚本实现。新建一个cut_log.sh,
#!/bin/sh # Program: # Auto cut nginx log script. # nginx日志路径 LOGS_PATH=/usr/local/nginx/logs TODAY=$(date -d ‘today‘ +%Y-%m-%d) # 移动日志并改名 mv ${LOGS_PATH}/error.log ${LOGS_PATH}/error_${TODAY}.log mv ${LOGS_PATH}/access.log ${LOGS_PATH}/access_${TODAY}.log # 向nginx主进程发送重新打开日志文件的信号 kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)
然后给上面的脚本授权
chmod u+x cut_log.sh
然后是加到定时任务中
crontab -e
0 0 * * * bash /usr/local/nginx/logs/cut_log.sh
Nginx之——日志按日期分割的实现(基于CentOS操作系统)
标签:centos 发送 error Oday cut today 自身 pat nginx log
原文地址:https://www.cnblogs.com/azhqiang/p/10244537.html