Apache2 Logging Conditional with multiple env set

时间:2015-10-26 17:52:29

标签: logging configuration apache2

所以我们在我们的SLB上启用了X-Forwarded-For,它正在工作,我通过link here进行了正确的日志记录工作,它说要使用这个SetEnvIF语句。

我们遇到的问题是,SLB还会通过GET /health.html文件检查5秒,这样就填满了我们的日志。我找到了一种让apache2停止记录特定文件的方法,但是我似乎无法找到办法同时执行X-Forward-For和Do not Log特定文件。

这是我的最后一次尝试,当我读到一篇博客,说你可以使用多个环境,然后通过一个','来分隔它们,而不是那个:(。

    #logs
    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 "^/health\.html$" dontlog

    CustomLog "/www/logs/access.log"  combined env=!forwarded,!dontlog
    CustomLog "/www/logs/access.log"  proxy env=forwarded

我感谢每个人的帮助。

感谢您的时间。

2 个答案:

答案 0 :(得分:1)

对于你的情况应该是:

HTML

最后一个可以是intval();,但我留下CustomLog /www/logs/access.log combined expr=(reqenv('forwarded')=='no'&&reqenv('dontlog')=='no') CustomLog /www/logs/access.log proxy expr=(reqenv('forwarded')=='yes') 作为env示例。

答案 1 :(得分:-1)

语法:

CustomLog file|pipe format|nickname [env=[!]environment-variable| expr=expression]
相关问题