apache ProxyPass: how to preserve original IP address apache ProxyPass: how to preserve original IP address apache apache

apache ProxyPass: how to preserve original IP address


You can get the original host from X-Forwarded-For header field.


The answer of JasonW is fine. But since apache httpd 2.4.6 there is a alternative: mod_remoteip

All what you must do is:

  1. May be you must install the mod_remoteip package

  2. Enable the module:

    LoadModule remoteip_module modules/mod_remoteip.so
  3. Add the following to your apache httpd config. Note that you must add this line not into the configuration of the proxy server. You must add this to the configuration of the proxy target httpd server (the server behind the proxy):

    RemoteIPHeader X-Forwarded-For# replace IP with the remote server you trustRemoteIPInternalProxy 10.123.123.1/24

See at http://httpd.apache.org/docs/trunk/mod/mod_remoteip.html for more information and more options.

Security warning! Only do this for proxies you trust. Otherwise someone can fake their IP.


This has a more elegant explanation and more than one possible solutions. http://kasunh.wordpress.com/2011/10/11/preserving-remote-iphost-while-proxying/

The post describes how to use one popular and one lesser known Apache modules to preserve host/ip while in a setup involving proxying.

Use mod_rpaf module, install and enable it in the backend server and add following directives in the module’s configuration. RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1

(2017 edit) Current location of mod_rpaf: https://github.com/gnif/mod_rpaf