访问日志不记录静态文件

[root@chy ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf 
(在虚拟主机配置文件里面增加如下内容)

    DocumentRoot "/data/wwwroot/111.com"
    ServerName www.111.com
    ServerAlias www.exaple.com 222.com
    #
     #
      #AllowOverride AuthConfig 
      #AuthName "111.com user auth"
        #AuthType Basic
       # AuthUserFile /data/.htpasswd 
      #  require valid-user
     # 
      #
     #
      #RewriteEngine on
        #RewriteCond %{HTTP_HOST} !^111.com$
       # RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L]
 
    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
 
主要的内容如下: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
    (需要注意的是要在customlog上面添加)
    这里我的出现了问题,按照上面的步骤后,记录了jpj的访问记录。
    解决问题的方法:这里需要注意的是curl 的时候必须是和ServerName www.111.com一致。

模拟一个图片测试

[root@chy ~]# cd /data/wwwroot/111.com/(进人此目录上传一张图片)
[root@chy 111.com]# ls
123.php  DSC_2800.jpg  index.php
(dsc_2800.jpg是上传的一张图片)
[root@chy 111.com]# mv DSC_2800.jpg lf.png
(因名字太长,改一个好记的名字)
[root@chy 111.com]# /usr/local/apache2.4/bin/apachectl graceful
[root@chy 111.com]# curl -x127.0.0.1:80 www.111.com/lf.png -I
HTTP/1.1 200 OK
Date: Wed, 02 Aug 2017 23:58:59 GMT
Server: Apache/2.4.27 (Unix) PHP/5.6.30
Last-Modified: Wed, 19 Oct 2016 08:52:35 GMT
ETag: "1bca7-53f33ee277ac0"
Accept-Ranges: bytes
Content-Length: 113831
Content-Type: image/png
(测试结果如上)
[root@chy 111.com]# tail -n2 /usr/local/apache2.4/logs/111.com-access_log 
192.168.212.1 - - [03/Aug/2017:07:02:10 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 1.1.4322; InfoPath.3)"
192.168.212.1 - - [03/Aug/2017:07:42:25 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"
(查看日志发现并没有记录png的访问记录)