Thursday, March 13, 2014

Enabling 'x-forwarded-for' header in apache configuration to log actual client ip address

To log the actual client IP address from the X-Forwarded-For header of a request using an Apache server, make the following changes to the apache httpd.conf file


  1. Log into the EC2 instance running apache httpd process.
  2. Navigate to /etc/httpd/conf or /opt/products/apache2/conf path and open the file httpd.conf.
  3. Search for the string: “LogFormat “%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined”
  4. Change the %h to %{X-Forwarded-For}i. The string now appears as “LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined”
  5. Save the httpd.conf file and restart httpd process (if running as service "sudo service httpd restart")

No comments:

Post a Comment