Gianluigi Leonardi
Gianluigi Leonardi

Reputation: 21

Tomcat issues with Host, Contexts and webapp double instances

/...too long and unclear explanation.../

In other way, I search the correct way to reach the site with just (one or more) domain name (then www.my_domain.it and not www.my_domain.it/appname), and all of these must point to the same instance of the webapp (so that from any domain name you access, the same Runtime data will always be displayed).

So, yes I have deployed the WAR file in tomcat/webapps folder, now, the correct to edit the conf/server.xml to get the result mentioned above, corresponds to one of the following?

1.

<Host name="my_domain.eu" appBase="webapps" unpackWARs="true" autoDeploy="true">
            <Alias>www.my_domain.eu</Alias>
            <Alias>www.my_domain.it</Alias>
            <Alias>www.my_domain_2.it</Alias>
            <Context path="" docBase="appname" debug="0" privileged="true" />
            ...
    </Host>

2.

<Host name="my_domain.eu" appBase="webapps/appname" unpackWARs="true" autoDeploy="true">
                <Alias>www.my_domain.eu</Alias>
                <Alias>www.my_domain.it</Alias>
                <Alias>www.my_domain_2.it</Alias>
                <Context path="" docBase="appname" debug="0" privileged="true" />
                ...
        </Host>

3.

<Host name="my_domain.eu" appBase="webapps/appname" unpackWARs="true" autoDeploy="true">
                <Alias>www.my_domain.eu</Alias>
                <Alias>www.my_domain.it</Alias>
                <Alias>www.my_domain_2.it</Alias>
                <Context path="/appname" docBase="appname" debug="0" privileged="true" />
                ...
        </Host>

4.

<Host name="my_domain.eu" appBase="webapps/appname" unpackWARs="true" autoDeploy="true">
                    <Alias>www.my_domain.eu</Alias>
                    <Alias>www.my_domain.it</Alias>
                    <Alias>www.my_domain_2.it</Alias>
 <!-- without context definition -->
                    ...
            </Host>

Otherwise, what is the correct solution? Thanks to all!

Upvotes: 0

Views: 217

Answers (1)

Olaf Kock
Olaf Kock

Reputation: 48087

I'm assuming that you have one of the instances of your app in the webapps directory, from where it's automatically deployed under its name. With the Context element, you can deploy applications from anywhere in the filesystem.

However, it's best practice to not edit server.xml with this information, but rather create individual context.xml files in conf/hostname, or just deploy to the host's webapps directory. Anything that you're configuring in server.xml requires a server restart if you want to change anything. Configuration outside of server.xml can be picked up at runtime, without restart.

Edit: Probably the takeaway of my previous answer wasn't clear:

When you use Context elements to configure: I'm proposing not to use the webapps directory for deploying your webapps. Just point to the directory where you actually deployed your webapp. This will make sure that no context is deploying your app from webapps/appname as /appname, even though your context definition points to /.

An alternative is to deploy your application with the name ROOT in webapps - this is a shortcut to actually deploy this webapp as / (careful: ALL CAPS for the directory- or file-name (ROOT.war) even on Windows if I remember correctly). But IMHO it would be clearer if you decide for either Context definition to determine the path (but deploy outside of appbase (webapps), or deployment in appbase (e.g. webapps) deployment.

Mocking around with appbase to point to some directory within webapps will make sure that you irritate anyone who is expecting that applications in webapps directory will deploy to Tomcat. That's an easy way to sink a lot of time into debugging phantom problems - don't do that.

Upvotes: 1

Related Questions