tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ron.vandenbranden@home" <>
Subject adding a global URI prefix for Tomcat web apps
Date Tue, 17 Apr 2012 12:25:06 GMT

I am setting up a reverse proxy configuration where all requests whose 
path starts with '/apps/' should be proxied by Apache to Tomcat. This 
IMO has 2 benefits: it makes it possible to reserve proxying to only the 
'/apps/' part of the URI space, and to use only a single proxy rule for 
all Tomcat apps (i.e. requests for any Tomcat app should just start with 

For example, requests for http://mydomain/apps/my_app/ should be proxied 
to http://localhost:8082/my_app/. Note the absence of the '/apps/' 
prefix in the Tomcat URI: 'my_app' lives in the regular location at 

I have achieved this using following Proxy rules in an Apache vhost.conf 

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

(Note: I have used ProxyPreserveHost since my Tomcat app needs access to 
the original host to generate further links). All goes well, except for 
absolute links that are generated by one part of my Tomcat app. Given 
above configuration, my Tomcat app will 'see' this request: 
http://mydomain/my_app, and hence generate links without the '/apps/' 
prefix that should trigger proxying for those links.

It took me some time, but I understand now that this is essential 
characteristic of proxying, and that there's no 'standard' way to pass 
on that '/apps/' prefix of the original request to the proxied app. 
Hence, I started to investigate another possibility, namely defining a 
global prefix for all Tomcat apps, and proxy the Tomcat apps with 
following settings:

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

This would proxy requests for http://mydomain/apps/my_app/ to 
http://localhost:8082/apps/my_app/. Since all apps on the Tomcat server 
will be accessed behind a proxy, I have no problem that this '/apps/' 
prefix will be required for all Tomcat apps.

So far, so good. Yet, I am struggling with the Tomcat side of this 
approach: finding a way to add a global path prefix for requests to 
Tomcat apps. The closest I got was this:
     1. don't touch the physical location of the Tomcat apps: leave them 
at ${CATALINA.HOME}/webapps
     2. change ${CATALINA.HOME}/conf/server.xml as follows:

     <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="false" deployOnStartup="false">
       <Context path="/apps/my_app" docBase="/my_app/" reloadable="true"/>

While this makes the my_app Tomcat app accessible at 
http://localhost:8082/apps/my_app/, it also suggests that all Tomcat 
apps should be defined manually in a separate <Context> element. This 
makes it less flexible to add new Tomcat web apps (and would actually 
mean more configuration work than declaring separate proxy rules for 
each app in the Apache configuration, without the '/apps/' prefix). I 
tried this:

       <Context path="/apps" docBase="/" reloadable="true"/>

(and @docBase variants such as "", or "."), but this doesn't work: no 
indication of any webapps being deployed in the Tomcat console output, 
and all requests return a 404 error.

Hence my question: is there a simple(r) way of 'declaring' a global URI 
prefix for Tomcat webapps?

Any advice much appreciated!


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message