0

I have Tomcat 6.x installed and Apache 2.2.x.

I want to map my Applications running on tomcat to sub-domains without having to specify ports and contexts.

I want: http://app1.mycompany.com/ to point to dev.mycompany.com:8080/app1/

I have tried creating Virtual Host entries different combonations of mod_proxy and mod_rewrite and using ajp but I can't get it set up to do this.

2 Answers 2

0

This should work:

<VirtualHost 0.0.0.0:80>
    ServerName app1.mycompany.com

    ProxyPass / http://dev.mycompany.com:8080/app1/
    ProxyPassReverse / http://dev.mycompany.com:8080/app1/
</VirtualHost>

Note however, that if the servlet at dev.mycompany.com uses the request URI to redirect the browser or generate a link in a document Apache doesn't understand (for example, a JNLP file), then it will fail to download because this will happen:

  1. The servlet detects the URI, /app1/
  2. The servlet generates the link, for example /app1/this_is_needed.jar
  3. The client tries to download the link, http://app1.mycompany.com/app1/this_is_needed.jar
  4. Since all requests gets redirected to dev.mycompany.com:8080/app1/, the request becomes http://dev.mycompany.com:8080/app1/app1/this_is_needed.jar, which doesn't exist.

This will not apply to html pages, because Apache will change the links (this is what the ProxyPassReverse is for). If you need to work around the error I described, you have two options:

  1. Make the webapp aware of the fact that it may have to serve paths different from the request URI. You'll need to find a way to specify these paths on the fly, using environmental variables (the SetEnv directive) for example
  2. Proxy the whole context, and in the webroot, place a simple page which redirects the user to /app1/
2
  • this doesn't work it just appends the /app1 over and over to the URL.
    – user35861
    Mar 9, 2011 at 4:39
  • @fuzzy-lollipop: The behavior you described suggests that you specified the same host name after the ServerName and the ProxyPass directives. The host names should be different.
    – Lacek
    Mar 9, 2011 at 21:43
0

I ended up ditching Apache Tomcat and just used Jetty and made the applications their own ROOT app context. Not optimal but it is light weight enough until I can figure out how to actually host multiple apps out of a Servlet container and have them seamlessly route to and from subdomains. Using Tomcat Virtual hosts directly outside Tomcat was suggested offline by someone, I will investigate that as well.

You must log in to answer this question.