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
maindomain.com and are adding 1 addon domain
~/appservers/apache-tomcat directory already includes
webapps directory that is default
appBase for localhost and is serving maindomain.com (from
webapps/ROOT). Please create
Please put JSP files into
webapps_domain1/domain1 directory. Alternatively you can put
webapps_domain1 directory and Tomcat will deploy the WAR.
- maindomain.com is the main domain (the main domain can point to a different directory such as ROOT, anyway this is only example).
- addondomain1.com is the domain that we want to add to Tomcat.
- You need create addondomain1.com as addon domains in cPanel.
- Please make sure you use correct nameservers for addondomain1.com.
- Create mappings - default mappings are enough. Use 'cPanel - Java Control Panel - Mappings' for this.
$CATALINA_HOME/conf/server.xml as follows:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- default content for default Host follows here --> </Host> <Host name="domain1.com" autoDeploy="true" appBase="webapps_domain1" unpackWARs="true"> <Alias>www.domain1.com</Alias> <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"/> <Context path="" docBase="domain1" debug="0" reloadable="true"/> </Host>
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
<Host name="domain1.com" autoDeploy="true" appBase="webapps" unpackWARs="true">