Skip to Main Content

Logging & Load Balancers - Getting the correct IP address

If you've set up a load balancer and have noticed that your Apache logs are showing all traffic coming from your load balancer's IP address instead of the user's, you can fix it by grabbing the X-Forwarded-For header and using that in the log format in httpd.conf:

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

Within your application code you can grab HTTP_X_FORWARDED_FOR from the server environment variables. 

ENV["HTTP_X_FORWARDED_FOR"]         # Ruby
$_SERVER["HTTP_X_FORWARDED_FOR"]   # PHP

 

 

Most RecentRSS

ArchiveRSS

March 2016 (1)
January 2016 (1)
September 2015 (1)
May 2015 (1)
April 2015 (1)
March 2015 (1)
February 2015 (2)
January 2015 (5)
September 2014 (2)
August 2014 (4)
July 2014 (1)
March 2014 (1)
November 2013 (3)
September 2013 (3)
July 2013 (6)
June 2013 (1)
May 2013 (1)
March 2013 (2)
February 2013 (3)
January 2013 (4)