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:
- Applications:
grailstest.war, springtest.war, playtest.war
- Respective domains:
grailshosting.info, javahosting.info, playtest.jvmhost.net
Now what needs to be done to have the applications accessible at root URLs?
- Assuming the alias playtest.jvmhost.net is already used as your primary domain in cPanel, add your 2 other domains (grailshosting.info, springhosting.info) as addon domains in cPanel. Make sure the domains have either our nameservers set at the domain registrar or are pointed to our server IP (consult welcome email for IP and namesevers).
- Stop the Tomcat using JCP panel or using
jk
alias from command line. - Upload
grailstest.war
,springtest.war
,playtest.war
to~/appservers/apache-tomcat-7.x.x/webapps
with FTP, SCP or cPanel's webDisk. - Edit
~/appservers/apache-tomcat-7.x.x/conf/server.xml
and add 3 virtual hosts just before last closing</Engine>
tag so that it reads:
<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 "%r" %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 "%r" %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 "%r" %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.
- Map all your domains (including the alias if it is not yet mapped) to your Tomcat with JCP - just clicking Restore Default Mappings will do. In Mapping section of JCP you will see your primary and addon domains.
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:
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.