Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat: two context paths for one webapp

Tags:

tomcat

The problem is: I have a web app and this web app is deployed to the $TOMCAT_HOME/webapps/XXX directory. I can reach that on the http://localhost:8080/XXX address BUT, I would like to reach the web app on the http://localhost:8080/YYY address too. I added the following to the server.xml:

<Server>
    <Service>
        <Engine>
            <Host>
                .......
                <Context path="/YYY" docBase="XXX"></Context>
            </Host>
        </Engine>
    </Service>
</Server>

It helped but the Tomcat started two web contexts and it caused some other problem. Is it possible to create a "multiple" address for one web app?

like image 779
AlBundy Avatar asked Nov 11 '09 16:11

AlBundy


People also ask

How do I change the context path of a web application?

To change the context root of a web application that is already available in the Eclipse workspace, simply right-click on the web project and call the “Properties” action from the context menu.

What is docBase in Tomcat context?

The docBase attribute is a path to the WAR file or exploded deployment directory. It is relative to the webapps directory, although an absolute path can be used. The path attribute is the one we are most interested in, as it defines the context path of the application.

What is Tomcat context path?

The context path refers to the location relative to the server's address which represents the name of the web application. By default, Tomcat derives it from the name of the deployed war-file. So if we deploy a file ExampleApp. war, it will be available at http://localhost:8080/ExampleApp.


1 Answers

The url of web application is assebled as follows:

PROTOCOL://DOMAIN:PORT/CONTEXT/pagename

The solutions for having same app on two distinct address are as follows:

  1. If you want to differ only in protocol (let's say between http, and https) then just have 2 connectors in server.xml.

  2. if you want to differ in DOMAIN name, then this is solved on DNS level.

  3. If you want to differ in context name (web application name), you should put apache in front (mod_proxy or mod_ajp) and then create a rewrite rule (mod_rewrite). let's say rewrite all from /a/* and /b/* to /c/*

  4. If you want to differ in page name, you should use servlet mappings.

Putting apache in front of tomcat via mod_proxy is very easy, there are multiple resources on the web. Very bad would be to duplicate applications (have everything loaded twice).

As for your question, i would advise agains duplication in server.xml.

<Context docBase="myapp" path="/address1" reloadable="true" />
<Context docBase="myapp" path="/address2" reloadable="true" />

This is killer for memory, as well as for session mechanisms, concurency, etc.

like image 182
Mitja Gustin Avatar answered Oct 19 '22 23:10

Mitja Gustin