apache访问日志和不记录映像

apache访问日志和不记录映像,apache,logging,Apache,Logging,我有这个Apache的日志格式 CustomLog /var/log/virtualmin/test_access_log "combined" env=!forwarded CustomLog /var/log/virtualmin/test_access_log "proxy" env=forwarded LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat

我有这个Apache的日志格式

CustomLog /var/log/virtualmin/test_access_log "combined" env=!forwarded
CustomLog /var/log/virtualmin/test_access_log "proxy" env=forwarded
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
SetEnvIf X-Forwarded-For ^.*\..*\..*\..* forwarded
我不想记录请求的图像文件,因此我使用以下方法:

SetEnvIf Request_URI \.jpg$ jpg-image
CustomLog /var/log/virtualmin/test_access_log "combined" env=!jpg-image
图像请求一直被记录,直到我对以下两行进行注释:

CustomLog /var/log/virtualmin/test_access_log "combined" env=!forwarded
CustomLog /var/log/virtualmin/test_access_log "proxy" env=forwarded
这似乎与转发和jpg图像不兼容。 我希望有人知道一个快捷方式来让它工作。

我也有同样的问题,customlog无法获得像中指定的那样的两个环境变量

我修复了此配置的问题,并根据您的需要进行了更改:

 # setup logFormat
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy

 #####################
 ## Define variable ##

 #If variable X-Forwarded-For is define with an ip define forwarded=true  (maybe use a better pattern match ) 
 SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded

 # if the variable X-Forwarded-For is empty set variable noforwarded=true
 SetEnvIf X-Forwarded-For "^$" noforwarded

 # If the URL request an jpg I set all variables (forwarded and noforwarded) to false
 SetEnvIf Request_URI \.jpg$ !forwarded !noforwarded

 ########################
 # Define the customlog #
 CustomLog /var/log/virtualmin/test_access_log combined env=noforwarded
 CustomLog /var/log/virtualmin/test_access_log proxy env=forwarded
因此,如果请求URI用于jpg,那么CustomLog永远不会与标准匹配,所有变量都设置为false。日志格式是正常的,因为转发的变量只有来自代理时才为真,而noforwarded只有在直接使用web服务器初始化连接时才为真

如果您想要一个包含所有日志的日志文件,您可以设置另一个变量,但这个变量永远不会更改。像这样:

SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
SetEnvIf X-Forwarded-For "^$" noforwarded
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" full_forwarded

SetEnvIf Request_URI \.jpg$ !forwarded !noforwarded

# Define the customlog
customLog /var/log/virtualmin/test_access_log combined env=noforwarded
CustomLog /var/log/virtualmin/test_access_log proxy env=forwarded
customLog /var/log/virtualmin/FULL_access_log combined env=!full_forwarded
CustomLog /var/log/virtualmin/FULL_access_log proxy env=full_forwarded
我希望它能有所帮助,也许你已经找到了解决办法,但对其他人来说