【CentOS 7架構11】,訪問日誌切割#171221

shallow丿ovephp


訪問日誌切割

  • 日誌一直記錄總有一天會把整個磁盤佔滿,因此有必要設置自動切割,並刪除舊的日誌文件
  • 把虛擬主機配置文件改爲以下: <VirtualHost :80> DocumentRoot "/data/wwwroot/www.111.com" ServerName www.111.com ServerAlias 111.com SetEnvIf Request_URI "..gif$" img SetEnvIf Request_URI "..jpg$" img SetEnvIf Request_URI "..png$" img SetEnvIf Request_URI "..bmp$" img SetEnvIf Request_URI "..swf$" img SetEnvIf Request_URI "..js$" img SetEnvIf Request_URI "..css$" img CustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/111.com-access_%Y%m%d.log 86400" combined env=!img </VirtualHost>
  • 從新加載配置文件-t,graceful
  • ls /usr/local/apache2.4/logs
[root@localhost 111.com]# vi /usr/local/apache2.4/conf/extra/httpd-vhosts.conf 
     44     <IfModule mod_rewrite.c>
     45         RewriteEngine on
     46         RewriteCond %{HTTP_HOST} !^111.com$
     47         RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L]
     48     </IfModule>
     49     ErrorLog "logs/111.com-error_log"
     50     SetEnvIf Request_URI ".*\.gif$" img
     51     SetEnvIf Request_URI ".*\.jpg$" img
     52     SetEnvIf Request_URI ".*\.png$" img
     53     SetEnvIf Request_URI ".*\.bmp$" img
     54     SetEnvIf Request_URI ".*\.swf$" img
     55     SetEnvIf Request_URI ".*\.js$" img
     56     SetEnvIf Request_URI ".*\.css$" img
     57     CustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/111.com-access_%Y%m%d.log 86400" combined env=!img
     58 </VirtualHost>

-l以當前系統切割日誌,若不指定以UTC切割,國內爲CST,差幾個時區 按天記錄,換算爲秒爲86400scss

[root@localhost 111.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@localhost 111.com]# /usr/local/apache2.4/bin/apachectl graceful
[root@localhost 111.com]# ls /usr/local/apache2.4/logs/
111.com-access_log  abc.com-access_log  access_log  httpd.pid
111.com-error_log   abc.com-error_log   error_log
[root@localhost 111.com]# curl -x 127.0.0.1:80 111.com/index.php
hello!111.com
[root@localhost 111.com]# cat /usr/local/apache2.4/logs/111.com-access_20171104.log 
127.0.0.1 - - [04/Nov/2017:22:30:22 +0800] "GET HTTP://111.com/index.php HTTP/1.1" 200 13 "-" "curl/7.29.0
[root@localhost 111.com]# ls /usr/local/apache2.4/logs/
111.com-access_20171104.log  111.com-error_log   abc.com-error_log  error_log
111.com-access_log           abc.com-access_log  access_log         httpd.pid
[root@localhost 111.com]# curl -x 127.0.0.1:80 111.com/1111.png -I
HTTP/1.1 200 OK
Date: Sat, 04 Nov 2017 14:35:19 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Last-Modified: Sat, 04 Nov 2017 14:35:19 GMT
ETag: W/"99ad-560d9271dfe00"
Accept-Ranges: bytes
Content-Length: 39341
Content-Type: image/png

[root@localhost 111.com]# curl -x 127.0.0.1:80 111.com/1111.png1 -I
HTTP/1.1 404 Not Found
Date: Sat, 04 Nov 2017 14:35:24 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Content-Type: text/html; charset=iso-8859-1

[root@localhost 111.com]# cat /usr/local/apache2.4/logs/111.com-access_20171104.log 
127.0.0.1 - - [04/Nov/2017:22:30:22 +0800] "GET HTTP://111.com/index.php HTTP/1.1" 200 13 "-" "curl/7.29.0"
127.0.0.1 - - [04/Nov/2017:22:35:24 +0800] "HEAD HTTP://111.com/1111.png1 HTTP/1.1" 404 - "-" "curl/7.29.0
相關文章
相關標籤/搜索