Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apache ProxyPass: how to preserve original IP address

We are using ProxyPass to redirect all "/r" requests to jboss on port 18080 as follows:

ProxyPreserveHost on ProxyPass /r http://localhost:18080/redirectService/ ProxyPassReverse /r http://localhost:18080/redirectService/ 

But, that causes the IP address logged in jboss's access log as "127.0.0.1". Does somebody know how can we preserve the original IP from where the request came in HttpServletRequest? We want to acesss it from jboss servlet request in doGet()

like image 299
ashweta Avatar asked Apr 17 '09 12:04

ashweta


People also ask

What is proxy preserve host?

The ProxyPreserveHost directive is used to instruct Apache mod_proxy, when acting as a reverse proxy, to preserve and retain the original Host: header from the client browser when constructing the proxied request to send to the target server.

What is ProxyPass and proxy pass reverse?

ProxyPassReverse will intercept those headers, and rewrite them to match the Apache proxy server. ProxyPass will create a reverse proxy. A reverse proxy (or gateway), appears to the client just like an ordinary web server. The client makes ordinary requests for content in the namespace of the reverse proxy.

What is the default proxy timeout in Apache?

Apache Default timeout is set to 300 seconds.


2 Answers

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

like image 148
andri Avatar answered Oct 06 '22 19:10

andri


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.

like image 43
Steffen Avatar answered Oct 06 '22 18:10

Steffen