首页 > 其他 > 详细

Nginx 访问日志轮询切割

时间:2017-02-19 11:17:28      阅读:323      评论:0      收藏:0      [点我收藏+]

Nginx 访问日志轮询切割

自己动手写Nginx 访问日志轮询切割,先说说思路,通过每天把访问日志文件重命名,并nginx 服务reload一下:如下图

技术分享

1、选看看虚拟主机的server标签内容

[root@web extra]# vim /application/nginx/conf/extra/www.conf
 server {
        listen       80;
        server_name  www.judong.org judong.org;
        location / {
            root   html/www;
            index  index.html index.htm;
        }
        access_log logs/access_www.log main;
  }


[root@web extra]# vim /application/nginx/conf/extra/bbs.conf
    server {
        listen       80;
        server_name  bbs.judong.org;
        location / {
            root   html/bbs;
            index  index.html index.htm;
        }
       access_log logs/access_bbs.log main;  ##添加访问日志
  }


[root@web extra]# vim /application/nginx/conf/extra/blog.conf  
server {
        listen       80;
        server_name  blog.judong.org;
        location / {
            root   html/blog;
            index  index.html index.htm;
        }
       access_log logs/access_blog.log main;
  }


轮询切割脚本cut_nginx_log.sh:

#!/bin/sh
Dateformat=`date +%Y%m%d`
Basedir="/application/nginx"
Nginxlogdir="$Basedir/logs"
Logname="access_www"
[ -d $Nginxlogdir ] && cd $Nginxlogdir||exit 1
[ -f ${Logname}.log ]||exit 1
/bin/mv ${Logname}.log ${Dateformat}_${Logname}.log
/bin/mv access_bbs.log ${Dateformat}_access_bbs.log
/bin/mv access_blog.log ${Dateformat}_access_blog.log
$Basedir/sbin/nginx -s reload



添加定时任务,每天0点进行切割:

[root@web scripts]# crontab -l
######cut nginx access.log########
00 00 * * *  /bin/sh /server/scripts/cut_nginx_log.sh >/dev/null 2>&1





本文出自 “pcjazz” 博客,请务必保留此出处http://520527.blog.51cto.com/510527/1899116

Nginx 访问日志轮询切割

原文:http://520527.blog.51cto.com/510527/1899116

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!