编辑httpd.conf 设置如下:
SetEnv IMAG 1
CustomLog logs/access_log combined env=!IMAG
这样记录文件access_log就不会记录ico|gif|jpg|png|bmp|swf的访问记录,同样也可以加上css|js才过滤css和js文件,效果很好.
但是这种记录限制只限制于做虚拟主机的时候没有同时设定记录文件的时候会参照这个方式记录在access_log文件里.不过httpd.conf里默认还有另外一个类似不记录虚拟主机日志的日志文件.
(设定:服务器是windows20003,装有apache2.3 php5 mysql zend gd)
参照:
#
# The location and format of the access logfile (Common Logfile Format).
# If you do not define any access logfiles within a
# container, they will be logged here. Contrariwise, if you *do*
# define per-
# logged therein and *not* in this file.
#
CustomLog logs/access.log common
这样会重复记录一个文件access.log ,所以可以注释掉上面那一行:
#CustomLog logs/access.log common
好了,现在Apache日志不记录图片文件设置原理方法已经知道了,但是虚拟主机里面的日志文件格式是什么呢?
先看我的虚拟主机的原来的配置内容:
ServerAdmin [email protected]
DocumentRoot E:\web\viatop
ServerName viatop.cn
ServerAlias *.viatop.cn
ErrorLog logs/viatop.cn-error_log
CustomLog logs/viatop.cn-access_log common
看看日志文件viatop.cn-access_log里面还是记录了图片的访问记录,也就是上面说的那个配置对在虚拟主机里设置的日志文件不起作用.
为什么会这样呢?
其实不是不起作用,而是作用域没有应用到而已,现在我改为:
ServerAdmin [email protected]
DocumentRoot E:\home\user\web\viatop
ServerName viatop.cn
ServerAlias *.viatop.cn
ErrorLog logs/viatop.cn-error_log
CustomLog logs/viatop.cn-access_log combined env=!IMAG
这样就好了,虚拟主机里面的日志文件也不会记录图片的访问记录了.