If your Apache web servers are sitting behind a Load Balancer, Varnish or similar you will be wanting to log the external IP of HTTP connections in your apache logs and not the IP of the load balancer etc. In Apache 2.2 this was usually done with mod_rpath. Since Apache 2.4 has it’s own module to deal with this and rpaf is not readily available for 2.4 then mod_remoteip is the way to go.

Configuration is pretty much the same as with rpaf.

1. Add a configuration file for the module including the name of the header and the IP/range of the load balancer. Replace x.x.x.x with the ip of your load balancer/proxy
# sudo vi /etc/apache2/mods-availbe/remoteip.conf

<IfModule remoteip_module>
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy x.x.x.x
</IfModule>

2. Enable the module
# sudo a2enmod remoteip

3. Change the Log Format  (%h -> %a)
#sudo vi /etc/apache2/apache2.conf

Before: LogFormat “%h %l %u %t \”%r\” %>s %O \”%{Referer}i\” \”%{User-Agent}i\”” combined
After: LogFormat “%a %l %u %t \”%r\” %>s %O \”%{Referer}i\” \”%{User-Agent}i\”” combined

4. Restart Apache
#sudo service apache2 restart

On a side note, if your using cloudflare there is a module that will look after that for you here

 

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>