mithra
mithra

Reputation:

apache tomcat fronting

Is it possible to specify multiple context paths for a single web application? For example I have a tomcat application myapp which runs on port 8080. I want to front this with apache such that localhost/app1 or localhost/app2 both are routed to myapp in tomcat How to achieve this?I don't want to use a redirect

Upvotes: 0

Views: 454

Answers (2)

Daniel Baktiar
Daniel Baktiar

Reputation: 1712

Yes, you can do that on your Apache Web Server setting. This option is irrelevant to Tomcat. You can do that to any application server behind Apache Web Server, be it Tomcat, Jetty, or even Another Apache Web Server running PHP scripts or static pages.

The actual setting depends on which method you are using to connect Apache Web Server to Tomcat.

For example if you use mod_proxy, the configuration will look like this:

ProxyPass /app1 http://192.168.11.25:8080/myapp
ProxyPassReverse /app1 http://192.168.11.25:8080/myapp
ProxyPass /app2 http://192.168.11.25:8080/myapp
ProxyPassReverse /app2 http://192.168.11.25:8080/myapp

I have just tried above setting on my machine to expose the same WebDAV Subversion in 2 different front URL.

Whether your application actually support that, that's another story. If your application need to specify the front URL and you are using mod_proxy e.g. installing application like Atlassian Confluence, this won't work at all. If your application doesn't need that, that will be good.

But you can always go down to lower level by creating a complex URL Rewrite (mod_rewrite) that should be able to workaround that as well.

Another thing you need to be aware of is the way your application handle session, URL, originating IP address etc. If it doesn't support that and you can't modify the application, than you are stuck.

Upvotes: 0

ZZ Coder
ZZ Coder

Reputation: 75456

No. There is no way to define 2 paths for the same app. You can specify 2 paths for the same WAR but it will still be 2 instances of the same application.

However, you can define your application as ROOT and check the path in your code. For example, put your application in webapps/ROOT and add this logic to your servlets,

String path = request.getPathInfo();

if (path.indexOf("/app1") >= 0)
   app1(request, response);
else if (path.indexOf("/app2") >= 0)
   app2(request, response);

Upvotes: 1

Related Questions