nginx按天切割access.log日志存放

  

1
vi /usr/local/nginx/sbin/cut_nginx_log.sh
1
2
3
4
5
6
7
8
9
#!/bin/bash
# This script run at 00:00

# The Nginx logs path
logs_path="/usr/local/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/nginx/nginx.pid`
1
crontab -e
1
00 00 * * * /bin/bash  /usr/local/nginx/sbin/cut_nginx_log.sh

来自张晏的脚本
http://blog.zyan.cc/nginx_php_v6/

您必须才能评论!

有 1 个评论

  1. nginx做静态文件下载服务器之安装与配置-老牛博客说道:

    […] 9、nginx日志文件access.log按天切割(自动删除待后续添加) 参照nginx按天切割access.log日志存放 […]

收藏
新建分类
没有账号? 忘记密码?