apache ProxyPass: how to preserve original IP address

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 trust
    RemoteIPInternalProxy 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.

Leave a Comment