Published on Dec 17 2011 in Java Tomcat

Many clients need to use the dedicated JVM/Tomcat for running multiple applications and also have the applications accessible at root URLs of multiple domains. This is quite easy with our setup.

For our example setup let's assume a client has 3 applications and 2 domains. He will use the alias we provide to each client for the third domain:

Now what needs to be done to have the applications accessible at root URLs?

<Host name="grailshosting.info" appBase="webapps" unpackWARs="true" autoDeploy="true">
            <Alias>www.grailshosting.info</Alias>
            <Context path="" docBase="grailstest" debug="0" privileged="true" />
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"   
                   prefix="localhost_access_log." suffix=".txt" 
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false" />
</Host>
    
<Host name="javahosting.info" appBase="webapps" unpackWARs="true" autoDeploy="true">
            <Alias>www.javahosting.info</Alias>
            <Context path="" docBase="springtest" debug="0" privileged="true" />
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"   
                   prefix="localhost_access_log." suffix=".txt" 
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false" />
</Host>
    
<Host name="playtest.jvmhost.net" appBase="webapps" unpackWARs="true" autoDeploy="true">
            <Context path="" docBase="playtest" debug="0" privileged="true" />
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"   
                   prefix="localhost_access_log." suffix=".txt" 
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false" />
</Host>

Note that docBase for each virtual host is different and the host treats the docBase as residing at its root URL (parameter path=""). To avoid the apps being deployed under all hosts you may also provide different appBase (e.g. webapps_playtest.jvmhost.net) for each Host. This should also decrease memory usage. Do not forget to create such new webapps directories before starting Tomcat.

List of domains available for mapping to application server in JCP
Note that addon domains are displayed/named a bit differently but it is cPanel flavor e.g. javahosting.info is shown as javahosting.playtest.jvmhost.net. After applying default mappings to one of the domains it will look like below:

List of default Apache to Tomcat mappings for a domain in JCP
Now start the Tomcat either from JCP or with command line alias js and access your domains - respective applications should respond from each of them.