Nginx access log polling and nginx log polling

Source: Internet
Author: User
Tags dateformat

Nginx access log polling and nginx log polling

Nginx access log polling and cutting script

 

 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

 

 

 

Configure 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   }

 

Configure 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; # add access logs 10} 11 ~

 

Configure 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   }

Test

 

 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

 

Configure a scheduled task to execute the script at zero o'clock every day

 

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.