Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm struggling with reverse proxying an app running in a Tomcat server on a closed port behind Apache. For convenience, say that I want to reverse proxy requests for 'http://mydomain/apps/my_app/' to the Tomcat app at 'http://localhost:8082/my_app/' on the remote server. All works fine with following proxy settings in an Apache vhost.conf file:

ProxyRequests       off
ProxyPass /apps/    http://localhost:8082/
ProxyPassReverse /apps/  http://localhost:8082/

Except for one part of the app, which generates a Java webstart file that is to be executed on the client and needs to make a connection to the Tomcat app at 'http://localhost:8082/my_app/webstart' (on the remote server).

Crux of the problem is that this connection obviously won't work, since a) the request for localhost will be interpreted relative to the client computer, and b) even if it would point to the remote server, port 8082 is closed there.

Hence, I figured out how ProxyPreserveHost can come to help, so that the host name of the original request will be propagated to the Java webstart request:

ProxyRequests       off
ProxyPreserveHost   on
ProxyPass /apps/    http://localhost:8082/
ProxyPassReverse /apps/  http://mydomain/

This works (even internal redirections in the proxied Tomcat app work by grace of the ProxyPassReverse setting)... almost. One problem remains: the URL that is used by the Java webstart file is missing the '/apps/' part, and will try to connect to 'http://mydomain/my_app/webstart', instead of 'http://mydomain/apps/my_app/webstart', wich will obviously fail since only requests starting with /apps/ are reverse proxied. Apparently, the proxied app does not 'see' the full original URL ('http://mydomain/apps/my_app/'), but only the part that's filtered out by the Proxy handling ('http://mydomain/my_app/').

Is there any Proxy setting I forgot that can make Apache pass on the path from the original URL to the proxied app?

Kind regards,

Ron

share|improve this question

1 Answer 1

up vote 0 down vote accepted

A proxy backend doesn't see the original request at all; that's the whole point of proxying.

You probably want the following:

ProxyPass /apps/ http://localhost:8082/apps/
ProxyPassReverse /apps/ http://localhost:8082/apps/

And make the tomcat apps available under that context.

share|improve this answer
    
Ok, thanks for the clarification. That's probably the more sensible option: I had come up with a (perhaps clumsy) workaround: adding an additional proxy rule for requests containing '/webstart/' somewhere in the URL: ProxyPassMatch /webstart/ http://localhost:8082/. Though I'm aware that this is an ad-hoc approach which probably misses other situations that rely on the backend's interpretation of the request URL. –  rvdb Apr 11 '12 at 15:22
    
do you happen to know how the tomcat apps can be made available under an 'extra' folder? In (my understanding of) standard Tomcat terms, this would involve wrapping the contents of the ${catalina_home}/webapps/ in an intermediary 'apps' folder: ${catalina_home}/webapps/apps/ in which the different apps reside? –  rvdb Apr 11 '12 at 20:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.