Get Real Visitor IP in Apache Logs running behind a Load Balancer

OBJECTIVE

The objective of this tutorial is to configure Apache webserver log settings to show the real visitor IP when Apache is running behind Load Balancer.

Many busy webservers run behind load balancers in order to distribute the traffic & increasing uptimes. When you run your Apache webserver behind a load balancer, the requests load balancer sends to apache are written in Apache logs with the IP address of your load balancer. To get the real visitors IP addresses in Apache logs, we need to do some modifications.

  • Goto /etc/httpd/conf directory
  • Open httpd.conf file, vim httpd.conf

The Default entry is:

LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”” combined
LogFormat “%h %l %u %t \”%r\” %>s %b” common

Change it like:

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

LogFormat “\”%{X-Forwarded-For}i\” %l %u %t \”%r\” %>s %b” common

 

Enjoy!!!

Leave a Reply

Your email address will not be published. Required fields are marked *