Nginx 日志切割
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx 日志切割相关的知识,希望对你有一定的参考价值。
#多虚拟主机日志切割
#!/bin/bash
for logs_path in `cd /opt/logs && ls ./`
do
cd /opt/logs/${logs_path}
mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
done
kill -USR1 `cat /opt/openresty/nginx/logs/nginx.pid `
#单个虚拟主机日志切割
#!/bin/bash
logs_path="/usr/local/webserver/nginx/logs/"
mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`
# crontab -e 增加一个定时任务
0 0 * * * /bin/bash /usr/local/nginx/sbin/cut-log.sh
以上是关于Nginx 日志切割的主要内容,如果未能解决你的问题,请参考以下文章