Apache logs and non-transparent load balancers
Typically, in a load balanced environment there are two types of modes that can be configured:
Transparent – Requests come into the load balancer and are transparently routed to the “real” servers behind it. In this setup, the real servers see the request as coming from the client IP address it was originally sent from. This typically requires all real servers to have it’s default gateway set as the load balancer.
Non-Transparent – In non-transparent mode, packets come into the load balancer, are re-written using NAT and then forwarded to the real servers behind it. In this scenario, all connections that come into the real servers appear to be originating from the load balancer.
If you are using any kind of analytics or stats software for your website, a load balancer in non-transparent mode will skew your data as all of your “hits” will appear to be coming from the same IP address (the load balancer). Fortunately, most load balancers have the ability to inject the “X-Fowarded-For” HTTP header into the request that makes it to the real server. This header will contain the original IP address which the request came from. We can use this information for more accurate website reporting.
Because of the flexibility of the Apache web server, we can alter what information goes into our log files. For example, if you wanted the client IP address field replaced with the X-Forwarded-For header data in your log files, you could add the following to your Apache 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 “^.*\..*\..*\..*” forwarded
CustomLog “logs/access_log” combined env=!forwarded
CustomLog “logs/access_log” proxy env=forwarded
This basically says “if the X-Forwarded-For header exists, use that value as the first column in our log file…otherwise, use the remote host’s IP address”. RackWire now offers load balanced solutions. By default, we will setup our load balanced services in non-transparent mode. We recommend that all customers who use our load balancer follow the example above so their Apache log files reflect accurate data. If you have questions about our load balanced solutions, please contact us today!









