Apache Remote ip
If you have Apache setup behind a forwarder (proxy,load balancer ,etc) and you want to get the actual ip address of incoming connections this post if for you.
By default apache will list the remote hostname/ip address of connections. This works if nothing else is in front of apache.
Once something else is forwarding traffic to apache, it will display the ip address of whatever is forwarding the traffic.
To fix this we use the remote ip module. Here is how (these locations/directions are valid for debian/ubuntu. Adjust accordingly)
Enable remoteip module
sudo a2enmod remoteip
Edit/create remoteip.conf in /etc/apache2/conf-available/remoteip.conf
RemoteIPHeader X-Forwarded-For
RemoteIPTrustedProxy ip.of.proxy
Setup a symlink from conf-available/remoteip.conf to conf-enabled/remoteip.conf
ln -s /etc/apache2/conf-available/remoteip.conf /etc/apache2/conf-enabled/remoteip.conf
Then adjust the logs in /etc/apache2/apache2.conf. In this example I am adjusting the log format for a vhost (vhost_combined is for vhost. combined is for the regular log).
From
LogFormat "%v:%p %h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"" vhost_combined
To
LogFormat "%v:%p %a %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"" vhost_combined
Basically you change %h to %a. %h is remote hostname/ip address %a is the client ip address before the forwarder. More log format information can be found here (apache docs)
test config with
apache2ctl configtest
restart apache
service apache2 restart
Check logs for client ip's. fin