Knowledge Base
MilesWeb / Cloud Servers

Steps to Setup Multiple Domain Names on a Single Apache Tomcat Server

Approx. read time : 3 min

Today, you will find people buying multiple domain names for their projects instead of choosing a single one.

Though it’s a fact that you may have completely different sites but one of the main benefits of having them is that when several domains lead to differently themed sites for different marketing campaigns or user experience.

Another benefit that can’t be ignored and is especially offered by MilesWeb is that you are able to have more than one domain running on a single environment. For example, there can be two different web applications on two different domains that run within a single Tomcat instance.

And the last one is the efficiency and scalability that supports your project’s future growth. Startups especially appreciate this particular option because they can begin with running a single environment for their applications by paying only for what is used and later in scale it up when required.

Let’s learn to set up multiple domain names on the Apache Tomcat server. You simply need to make some minor changes within Tomcat configuration files as described below.

Related: What is Apache Tomcat Hosting?

1. Log into the dashboard of MilesWeb PaaS powered by Jelastic and click the New Environment button:

2. In the Environment Topology dialog, select your web application server (e.g. Tomcat 9), and specify your environment name, for example, multibinding.

Your environment will be created successfully in a minute.

3. It is possible to buy domain names and set up them instead of default ones by adding CNAME record or by setting A Records. Refer the Custom External Domain Name Binding document.

4. Again go to the MilesWeb dashboard, click the Settings button for your environment and bind domain names.

In our case, for the first domain name we will use tomcatfirst.tk, and for the second we will use tomcatsecond.tk.

5. Now it’s time to deploy the projects.

  • Go to the Deployment Manager and upload the Java application file and click on Deploy to button. As an example, we use Hello World which is by default available in Deployment Manager.

Select your environment when the Deploy form appears and mention the context (tomcatfirst, in our case). After this, click on the Deploy button.

  • Next, upload the second application archive. For this, we will use modified Hello World (the words “You did it!” are recolored in red) so that we can see the difference in the final steps. Deploy this application to the same environment using different context (e.g. tomcatsecond).

After deployment is completed, you will have two applications deployed in your environment.

6. For Tomcat, click on Сonfig button and go to server.xml file (the /opt/tomcat/conf directory).

Add Host tags for each domain you want to bind:

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

7. Next, save the changes and restart Tomcat.

8. After the Tomcat gets restarted, you can check the results. Both your applications will be available via the custom domain names that are running on a single Tomcat server.

Note: If you want to re-deploy an application to the Apache Tomcat server with already configured server.xml, you will need to comment < Host > block prior to re-deploying and uncomment it afterwards.

It is quite easy, right? After practicing this tutorial, you have got an idea to set up multiple domain names to increase your Java application’s usability, efficiency and scalability as well as save your costs without the need to configure separate web servers.

Just choose the MilesWeb PaaS service and try it out on your own or request for a demo.

Pallavi Godse
Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.
Need help? We’re always here for you.