tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pid <...@pidster.com>
Subject Re: adding a global URI prefix for Tomcat web apps
Date Tue, 17 Apr 2012 19:16:42 GMT
On 17/04/2012 13:25, ron.vandenbranden@home wrote:
> Hi,
> 
> 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
> '/apps/').
> 
> 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
> ${CATALINA_HOME}/webapps/my_app.
> 
> I have achieved this using following Proxy rules in an Apache vhost.conf
> file:
> 
>   ProxyPreserveHost    on
>   ProxyPass            /apps/    http://localhost:8082/
>   ProxyPassReverse    /apps/    http://mydomain/

From the docs:

 ProxyPass        /mirror/foo/ http://backend.example.com/
 ProxyPassReverse /mirror/foo/ http://backend.example.com/

 http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassreverse

ProxyPassReverse is designed to be used to address the situation you
describe, you just appear to be using it incorrectly.

Can you try again, with the correct 2nd parameter for this directive?


p

> (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"/>
>     </Host>
> 
> 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!
> 
> Ron
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


-- 

[key:62590808]


Mime
View raw message