Tomcat virtual hosts.
Host many domains with different web applications

Let's assume your primary domain is domain1.com. In our environment it is by default mapped to your Tomcat and reads from webapps/ROOT. To host additional domain (domain2.com) and have a different web application at the domain's root URL follow the below steps.

  1. Add the domain in cPanel as addon domain (this will create DNS records for it).
  2. Set our nameservers for your domain in your domain registrar control panel (if you registered the domain with us the nameservers are already set).
  3. In Java Control Panel's Mappings section you will see it as domain2.domain1.com (this is cPanel's equivalent for domain2.com). Choose it and click 'Restore Default Mappings'.
  4. In Tomcat's conf/server.xml add new Host entry with docBase pointing to the application you want to host at domain2.com root URL. For example if you uploaded dom2app.war to Tomcat's webapps it will autodeploy to webapps/dom2app. Your Host may then read:
    <Host name="domain2.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
        <Alias>www.domain2.com</Alias>
        <Context path="" docBase="dom2" 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: Enter new Host just before last '' tag line.
  5. Restart your Tomcat from command line or Java Control Panel.

The above procedure will also work for subdomains.

 

Live Demo Panel (user:demo, password:demo2011)

Go Live in Just 10 minutes!