Combining logging with rules for X-Forwarded-For AND not logging specific IP’s

Discussion in 'Apache' started by satelit2, Feb 18, 2010.

  1. #1
    Hello

    Our apache is behind haproxy, our internal staff connects directly to the web server.
    To log both types of IP’s we use the following configuration:

    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 "^.*\..*\..*\..*" is-forwarder
    CustomLog access_log combined env=!is-forwarder
    CustomLog access_log proxy env=is-forwarder


    Since Haproxy sends a heartbeat request once a second to apache to monitor the backend server’s health, the log file gets large very fast. Not to mention, these log entries are useless.

    Normally, it would have been possible to filter this:

    SetEnvIf Remote_Addr "192\.168\.0\.1" dontlog
    CustomLog access_log proxy env=! dontlog

    However there can only be one env=… entry and it is already being used by: env=!is-forwarder

    Is there a way to combine these two rules to keep loggin the right IP’s AND avoid logging the internal IP?

    David
     
    satelit2, Feb 18, 2010 IP