Multiple Domain Names on Tomcat Server

Using multiple domains gives you the possibility to increase the usability, efficiency and scalability of your application and save your costs without having to setup separate instances. Below is another way to do the same thing but a little differently. To be exact , to realize multiple domains setting at the http headers' layer using header Host. Let's get started!

Set Up Multiple Domains

  1. Log into the
    Jelastic Manager
  2. While in Jelastic dashboard, click the Create environment button:


  3. In the Environment Topology dialog, pick your application server (for example, Tomcat 7), and type your environment name, for example, multibinding.


  4. In a minute your environment will be successfully created.


  5. With Jelastic it is possible to set your own domain name for your URL instead of using your hoster domain name. So, buy domain names for your environment. It can be done in two ways: by adding CNAME record or by setting A Records.

    Read more here.

  6. Go back to the Jelastic dashboard, click the Settings button (the wrench icon) for your environment and bind your domains. In our case the URLs are: firstdomain.com and seconddomain.com.


  7. Upload your war files/file to the Deployment manager and deploy them to different contexts.




  8. Click on config button for Tomcat, navigate to server.xml file (the /opt/tomcat/conf directory) and set the configuration for host multiple domains (add Host tags for each domain you want to bind).
  9. 	<Host name="external.domain.tld" appBase="webapps/context_name" autoDeploy="true">
    	<Alias>external.domain.tld</Alias>
    	<Context path="" docBase="${catalina.base}/webapps/context_name"/>
    	</Host>
    	...
    


  10. Save the changes and restart Tomcat.

  11. Now you can check the results. You application/s will be available through the specified domain names.



Note: if you want to redeploy an application to the Tomcat instance with already configured server.xml, you need to comment < Host > block before redeploying and uncomment it afterwards.