Apache日志不记录图片文件设置方法

一:编辑httpd.conf 设置如下

<FilesMatch “\.(ico|gif|jpg|swf)”>  —设置需要过滤的图片格式
SetEnv IMAG 1
</FilesMatch>
CustomLog logs/access_log combined env=!IMAG

二:在虚拟主机下针对每个域名的过滤

view /usr/local/apache2/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot “/www/web/www/passport.test.com.cn”
ServerName passport.test.com.cn
ErrorLog “/www/logs/passport-error_log”
<FilesMatch “\.(bmp|gif|jpg|swf|png)”>
SetEnv IMAG 1
</FilesMatch>
CustomLog “|/usr/local/sbin/cronolog /www/logs/passport.test.com.cn-access_log.%Y%m%d” combined env=!IMAG
</VirtualHost>

此条目发表在Apache分类目录。将固定链接加入收藏夹。