码迷,mamicode.com
首页 > 其他好文 > 详细

日志不记录静态文件,日志切割,静态元素过期时间

时间:2018-03-05 22:23:09      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:日志   静态过滤   

访问日志不记录静态文件

技术分享图片

1.过滤静态文件:修改虚拟主机配置文件

[root@weixing01 ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf 
<IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{HTTP_HOST} !^111.com$
        RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L]
   </IfModule>

    ErrorLog "logs/111.com-error_log"
    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 "logs/111.com-access_log" combined env=!img
</VirtualHost>

2.进行验证,重新加载:

[root@weixing01 ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@weixing01 ~]# /usr/local/apache2.4/bin/apachectl graceful

3.测试:jpg1,jpg

[root@weixing01 ~]# curl -x127.0.0.1:80 111.com/alsdkjfakjg.jpg1  -I
HTTP/1.1 404 Not Found
Date: Mon, 05 Mar 2018 13:20:01 GMT
Server: Apache/2.4.29 (Unix) PHP/7.1.6
Content-Type: text/html; charset=iso-8859-1

[root@weixing01 ~]# tail /usr/local/apache2.4/logs/111.com-access_log 
192.168.188.1 - - [03/Mar/2018:10:01:35 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:36 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:42 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:51 +0800] "GET / HTTP/1.1" 301 223 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:51 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:36 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:43 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:49 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
127.0.0.1 - - [05/Mar/2018:21:16:51 +0800] "HEAD HTTP://111.com/alsdkjfakjg.jpg HTTP/1.1" 404 - "-" "curl/7.29.0"
127.0.0.1 - - [05/Mar/2018:21:20:01 +0800] "HEAD HTTP://111.com/alsdkjfakjg.jpg1 HTTP/1.1" 404 - "-" "curl/7.29.0"
[root@weixing01 ~]# curl -x127.0.0.1:80 111.com/alsdkjfak1231jg.jpg  -I
HTTP/1.1 404 Not Found
Date: Mon, 05 Mar 2018 13:20:24 GMT
Server: Apache/2.4.29 (Unix) PHP/7.1.6
Content-Type: text/html; charset=iso-8859-1

[root@weixing01 ~]# tail /usr/local/apache2.4/logs/111.com-access_log 
192.168.188.1 - - [03/Mar/2018:10:01:35 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:36 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:42 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:51 +0800] "GET / HTTP/1.1" 301 223 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:51 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:36 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:43 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:49 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
127.0.0.1 - - [05/Mar/2018:21:16:51 +0800] "HEAD HTTP://111.com/alsdkjfakjg.jpg HTTP/1.1" 404 - "-" "curl/7.29.0"
127.0.0.1 - - [05/Mar/2018:21:20:01 +0800] "HEAD HTTP://111.com/alsdkjfakjg.jpg1 HTTP/1.1" 404 - "-" "curl/7.29.0"
[root@weixing01 ~]# curl -x127.0.0.1:80 111.com/alsdkjfak1231jg.jpg12  -I
HTTP/1.1 404 Not Found
Date: Mon, 05 Mar 2018 13:20:48 GMT
Server: Apache/2.4.29 (Unix) PHP/7.1.6
Content-Type: text/html; charset=iso-8859-1

[root@weixing01 ~]# tail /usr/local/apache2.4/logs/111.com-access_log 
192.168.188.1 - - [03/Mar/2018:10:01:36 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:42 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:51 +0800] "GET / HTTP/1.1" 301 223 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:51 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:36 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:43 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:49 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
127.0.0.1 - - [05/Mar/2018:21:16:51 +0800] "HEAD HTTP://111.com/alsdkjfakjg.jpg HTTP/1.1" 404 - "-" "curl/7.29.0"
127.0.0.1 - - [05/Mar/2018:21:20:01 +0800] "HEAD HTTP://111.com/alsdkjfakjg.jpg1 HTTP/1.1" 404 - "-" "curl/7.29.0"
127.0.0.1 - - [05/Mar/2018:21:20:48 +0800] "HEAD HTTP://111.com/alsdkjfak1231jg.jpg12 HTTP/1.1" 404 - "-" "curl/7.29.0"

访问日志切割

技术分享图片
1.打开虚拟主机配置文件:

[root@weixing01 111.com]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf 
    CustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/111.com-access_%Y%m%d.log 86400" combined env=!img

2.重新加载:

[root@weixing01 111.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@weixing01 111.com]# /usr/local/apache2.4/bin/apachectl graceful

3.验证:

[root@weixing01 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@weixing01 111.com]# curl -x127.0.0.1:80 111.com/123.php
123.php[root@weixing01 111^C
[root@weixing01 111.com]# ls /usr/local/apache2.4/logs
111.com-access_20180305.log  111.com-error_log   abc.com-error_log  error_log
111.com-access_log           abc.com-access_log  access_log         httpd.pid
[root@weixing01 111.com]# cat /usr/local/apache2.4/logs/111.com-access_20180305.log 
127.0.0.1 - - [05/Mar/2018:21:51:50 +0800] "GET HTTP://111.com/123.php HTTP/1.1" 200 7 "-" "curl/7.29.0"

静态元素过期时间

技术分享图片

304表示来自缓存技术分享图片
1.打开虚拟主机配置文件

[root@weixing01 111.com]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf 
   </IfModule>
<IfModule mod_expires.c>
    ExpiresActive on 
    ExpiresByType image/gif  "access plus 1 days"
    ExpiresByType image/jpeg "access plus 24 hours"
    ExpiresByType image/png "access plus 24 hours"
    ExpiresByType text/css "now plus 2 hour"
    ExpiresByType application/x-javascript "now plus 2 hours"
    ExpiresByType application/javascript "now plus 2 hours"
    ExpiresByType application/x-shockwave-flash "now plus 2 hours"
    ExpiresDefault "now plus 0 min"
</IfModule>

2.重新加载

[root@weixing01 111.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@weixing01 111.com]# /usr/local/apache2.4/bin/apachectl graceful

3.检测模块是否开启,没有打开,修改主配置文件:

[root@weixing01 111.com]# vim /usr/local/apache2.4/conf/httpd.conf
LoadModule env_module modules/mod_env.so
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
#LoadModule unique_id_module modules/mod_unique_id.so
[root@weixing01 111.com]# /usr/local/apache2.4/bin/apachectl -M |grep expire
 expires_module (shared)

4.验证:有cache control一行

[root@weixing01 111.com]# curl -x127.0.0.1:80 111.com/bj.jpg -I
HTTP/1.1 200 OK
Date: Mon, 05 Mar 2018 14:14:26 GMT
Server: Apache/2.4.29 (Unix) PHP/7.1.6
Last-Modified: Tue, 02 May 2017 15:30:36 GMT
ETag: "7e25-54e8c38a0bf00"
Accept-Ranges: bytes
Content-Length: 32293
Cache-Control: max-age=86400
Expires: Tue, 06 Mar 2018 14:14:26 GMT
Content-Type: image/jpeg

日志不记录静态文件,日志切割,静态元素过期时间

标签:日志   静态过滤   

原文地址:http://blog.51cto.com/13517254/2083235

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!