Set Multiple Domains on Tomcat server

Multiple Domain Names on Tomcat Server

Set up multiple domain names on the Tomcat server in order to increase the usability, efficiency, and scalability of your application, as well as save your costs without having to configure separate instances. For this, make some minor adjustments within Tomcat configuration files as described below.

1. Log into the Cloudjiffy PaaS dashboard and click the New environment button:
                

2. In the Environment Topology dialog, pick your application server (e.g. Tomcat 9), and type your environment name, for example, multi binding.
 
In a minute your environment will be successfully created.

3. Now you need to deploy the projects. You can buy and set up your own domain names instead of default ones by adding CNAME record or by setting A Records. Read more in the Custom External Domain Name Binding document.

4. Go back to the Cloudjiffy dashboard, click the Settings button for your environment and bind your domains.


In our example, you’ll use tomcatfirst.tk for the first domain name, and tomcatsecond.tk for the second.
5. Now you need to deploy the projects.
 
  • Upload the application file to the Deployment Manager and press Deploy to button.
    As an example, you can use Hello World which is available in the Deployment Manager by default.



When the Deploy form appears choose your environment and assign the context (tomcat first, in our case). Then press the Deploy button.

  • Upload the second application archive. We will use modified Hello World (the words “I did it!” are recolored in red) just to see the difference at the final steps.

    Then deploy this application to the same environment but with a different context, (e.g. tomcatsecond).

When the deployment is finished two have two applications deployed in your environment.


6. Now click on Сonfig button for Tomcat and navigate to server.xml file (the /opt/tomcat/conf directory).

Add Host tags for each domain you want to bind:

1
2
3
4
 
    external.domain.tldAlias>
    
Host>

In our sample, we add the following code to server.xml file:

1
2
3
4
5
6
7
8
9
 
tomcatfirst.tkAlias>
 
Host>
 
 
tomcatsecond.tkAlias>
 
Host>


7. Save the changes and restart Tomcat.

8. Now you can check the results. Both your applications will be available through the specified domain names running on a single Tomcat server.

 
 
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 afterward.


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 13183