Published on May 18 2018 in Java Tomcat

With Tomcat running on JVM Host dedicated JVM you have full control over configuration files. You may host multiple domains and map them to particular web applications. First step is to map a domain or a path under it to the Tomcat (this is done with mod_jk or mod_proxy_ajp using our Java Control Panel), second step is to add virtual host in server.xml. See the below example.

Let’s assume you have 1 primary domain and are adding 1 addon domain Your ~/appservers/apache-tomcat directory already includes webapps directory that is default appBase for localhost and is serving (from webapps/ROOT). Please create webapps_domain1 directory.

Please put JSP files into webapps_domain1/domain1 directory. Alternatively you can put domain1.war into webapps_domain1 directory and Tomcat will deploy the WAR.

  1. is the main domain (the main domain can point to a different directory such as ROOT, anyway this is only example).
  2. is the domain that we want to add to Tomcat.
  3. You need create as addon domains in cPanel.
  4. Please make sure you use correct nameservers for
  5. Create mappings - default mappings are enough. Use ‘cPanel - Java Control Panel - Mappings’ for this.
  6. Configure $CATALINA_HOME/conf/server.xml file.

Please edit $CATALINA_HOME/conf/server.xml as follows:

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
    <!-- default content for default Host follows here -->

<Host name="" autoDeploy="true" appBase="webapps_domain1" unpackWARs="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"/>
     <Context path="" docBase="domain1" debug="0" reloadable="true"/> 

Restart Tomcat using JavaCP or shell (SSH) and your are done.

Keeping applications for multiple domains under default (and common) webapps

This approach is also possible but uses slightly more memory as each Host detects all applications (WARs) inside common webapps and deploys them. All apps are then aaccessible via every domain (Host) which may also be unwanted behavior. Server.xml configuration for this approach would only differ in appBase for the new Hosts (it will be webapps):

<Host name="" autoDeploy="true" appBase="webapps" unpackWARs="true">