【CentOS 7架构11】,访问日志切割#171221

  • 来源:
  • 更新日期:2018-04-26

摘要:hellopasswd 访问日志切割 日志一直记录总有一天会把整个磁盘占满,所以有必要设置自动切割,并删除旧的日志文件 把虚拟主机配置文件改成如下: DocumentRoot \"/data/wwwroot/www.111.com\" ServerName www.111.com ServerAlias 111.com SetEnvIf Request_URI

hellopasswd


002UASMrzy7605pjKJv15&690.jpg

访问日志切割 日志一直记录总有一天会把整个磁盘占满,所以有必要设置自动切割,并删除旧的日志文件 把虚拟主机配置文件改成如下: <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,差几个时区 按天记录,换算为秒为86400s

[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


修改与 171221