Members Area - Knowledgebase



How do I get Apache to log the IP address through my Load Balancer?

The Load Balancer pushes through the HTTP_X_Forwarded_For of the original IP address. Apache currently logs the remote_addr which is the internal IP address of the network interface.

Within a PHP script you can look at the Environment Variable: $_SERVER['HTTP_X_FORWARDED_FOR'] to get the IP address of the incoming connection.

To change the Apache logs (httpd.conf):

Locate the following line and comment it out like below:

#LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined

Add the following line to your config file:

LogFormat "%{X-Forwarded-For}i %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined

Note: the combine line is not the default configuration, common is.  Comment the common line out for this to work. 



Was this answer helpful?

Add to Favourites
Print this Article