Nginx 訪問日誌輪詢切割,nginx日誌輪詢切割

來源:互聯網
上載者:User

Nginx 訪問日誌輪詢切割,nginx日誌輪詢切割

Nginx 訪問日誌輪詢切割指令碼

 

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

 

 

 

配置www.conf

 

 1 [root@lnmp02 scripts]# vim /application/nginx/conf/extra/www.conf  2  server { 3         listen       80; 4         server_name  www.judong.org judong.org; 5         location / { 6             root   html/www; 7             index  index.html index.htm; 8         } 9         access_log logs/access_www.log main;10   }

 

配置bbs.conf

 

 1 [root@lnmp02 scripts]# vim /application/nginx/conf/extra/bbs.conf  2     server { 3         listen       80; 4         server_name  bbs.judong.org; 5         location / { 6             root   html/bbs; 7             index  index.html index.htm; 8         } 9        access_log logs/access_bbs.log main;  ##添加訪問日誌10   }11 ~         

 

配置blog.conf

 1 [root@lnmp02 scripts]# vim /application/nginx/conf/extra/blog.conf    2 server { 3         listen       80; 4         server_name  blog.judong.org; 5         location / { 6             root   html/blog; 7             index  index.html index.htm; 8         } 9  access_log logs/access_blog.log main;10   }

測試

 

 1 [root@lnmp02 scripts]# ll /application/nginx/logs/ 2 total 40 3 -rw-r--r--. 1 root root   756 Mar  3 22:07 20160315_access_www.log  4 -rw-r--r--. 1 root root     0 Mar 15 09:27 20160316_access_www.log 5 -rw-r--r--. 1 root root     0 Mar 17  2016 20160317_access_bbs.log 6 -rw-r--r--. 1 root root     0 Mar 17  2016 20160317_access_blog.log 7 -rw-r--r--. 1 root root     0 Mar 17  2016 20160317_access_www.log 8 -rw-r--r--. 1 root root     0 Mar 17  2016 access_bbs.log 9 -rw-r--r--. 1 root root     0 Mar 17  2016 access_blog.log10 -rw-r--r--. 1 root root 22177 Mar  3 22:06 access.log11 -rw-r--r--. 1 root root     0 Mar 17  2016 access_www.log12 -rw-r--r--. 1 root root  2088 Mar 17  2016 error.log13 -rw-r--r--. 1 root root     5 Mar  3 19:31 nginx.pid

 

配置定時任務使得每天0點整執行指令碼

 

1 [root@lnmp02 scripts]# crontab -l2 ######cut nginx access_www.log########3 00 00 * * *  /bin/sh /server/scripts/cut_nginx_log.sh >/dev/null 2>&1

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.