Reverse proxy with Apache ProxyPass redirects instead of transparent passing

I have a web application running inside Tomcat at http://<server>:8080/app/portal/ . I want the world to see this application through the URL http://<server>/portal/ .

To do this, I configured a reverse proxy with Apache 2.2. According to the documentation for ProxyPass , I expect the reverse proxy to transparently forward all requests. My browser should never know the Tomcat URL.

Here is my configuration:

There are no virtual hosts, I added these lines to my httpd.conf

 <Location /portal/> AllowOverride All RewriteEngine On ProxyPass http://server:8080/app/portal/ ProxyPassReverse http://server:8080/app/portal/ </Location> 

When I use Firefox to open http://<server>/portal/ , I get 302 Moved Temporarily, and all subsequent calls go directly from my browser to http://<server>:8080/app/portal/ . My browser points to this URL.

This is not what I expected from a reverse proxy. Did I misconfigure, or did I misunderstand the purpose of reverse proxies? What should I do to achieve the desired behavior?

+7
source share
3 answers

I tried to comment on the answer from davidethell, but could not format the lines correctly, so here is what I found out:

The problem was that the reverse proxy seems to work only with the URL where the war is deployed in my Tomcat, and NOT with the servlet inside Tomcat. This results in 2 rewrites, one of which is a reverse proxy, and one of them just rewrites everything behind.

 RewriteEngine On RewriteRule ^/portal/$ /portal/portal RewriteRule ^/portal(.+) http://<server>:8080/app$1 [P] 
+5
source

Have you tried using the mod_rewrite Proxy option instead of ProxyPass? Something like:

 RewriteRule ^$ http://server:8080/app/portal/ [P] 
+1
source

You forgot to add the following option to the reverse proxy configuration:

 ProxyPreserveHost On 

You can achieve the same behavior with Url Rewriting, but this is not recommended in the documentation.

+1
source

All Articles