Nginx 접근 로그 폴 링 절단

7467 단어
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.log
10 /bin/mv access_blog.log ${Dateformat}_access_blog.log
11 $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.log
10 -rw-r--r--. 1 root root 22177 Mar  3 22:06 access.log
11 -rw-r--r--. 1 root root     0 Mar 17  2016 access_www.log
12 -rw-r--r--. 1 root root  2088 Mar 17  2016 error.log
13 -rw-r--r--. 1 root root     5 Mar  3 19:31 nginx.pid

 
매일 0 시 정각에 스 크 립 트 를 실행 할 수 있 도록 정시 작업 설정
 
1 [root@lnmp02 scripts]# crontab -l
2 ######cut nginx access_www.log########
3 00 00 * * *  /bin/sh /server/scripts/cut_nginx_log.sh >/dev/null 2>&1

좋은 웹페이지 즐겨찾기