Get proxied client IP with apache

Tue 10 February 2015
By alex

Using mod_remoteip and modifying apache's log format, real client IP addresses can easily be captured

Enable and configure mod_remoteip

LoadModule remoteip_module modules/
<IfModule mod_remoteip.c>
    RemoteIPHeader          X-Forwarded-For  # YMMV for different load balancers

Modify log variables

Replace the remote hostname variable, %h, with the client ip variable provided by mod_remoteip, %a


LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined


LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

For more logging variables see the docs
Apache Module mod_log_config