Multiple Domains for Tomcat

Multiple Domain Names on Tomcat Server

A single Tomcat environment can serve several applications through different custom domain names. Each domain is mapped to its own application context through Tomcat virtual-host settings.

This setup can reduce infrastructure overhead because separate Tomcat environments are not required for every domain-based application.

Create the Tomcat Environment

1Open the topology wizard

Sign in to the platform dashboard and click New Environment.

New Environment button
Start environment creation from the dashboard toolbar.

2Select Tomcat

Choose a Tomcat application server, configure the required resources, enter an environment name such as multibinding, and create the environment.

Tomcat topology wizard
Select Tomcat and define the environment resources and name.

After provisioning completes, the Tomcat environment appears in the dashboard.

New Tomcat environment
The Tomcat environment is ready for domain binding and application deployment.

Bind the Custom Domains

Prepare the required DNS records for every custom domain. Depending on the platform and DNS configuration, use a CNAME record or the relevant A records.

3Open environment settings

Click the environment Settings button and open Custom Domains.

Environment Settings button
Open the environment settings panel.

4Bind each domain

Enter the first custom domain, click Bind, and repeat the process for the remaining domains.

Bind custom domains
Bind all custom domains to the same Tomcat environment.
The example below uses two domains and two deployment contexts. Replace them with your actual domain names and application-context names.

Deploy the Applications

5Upload the first application

Add the application archive to Deployment Manager and click Deploy to….

Deploy the first application
Select the first application package for deployment.

Select the Tomcat environment and assign a unique context, for example tomcatfirst.

Assign the first Tomcat context
Deploy the first application to its own context.

6Deploy the second application

Upload the second archive and deploy it to the same environment with a different context, such as tomcatsecond.

Deploy the second application
Assign a separate context to the second application.

After deployment, both contexts should appear under the application-server layer.

Two applications deployed to Tomcat
Two application contexts deployed to one Tomcat environment.

Configure Tomcat Virtual Hosts

7Open server.xml

Click Config for the Tomcat layer and open /opt/tomcat/conf/server.xml.

Open Tomcat server.xml
Open server.xml from the Tomcat configuration directory.

Add one <Host> block for every custom domain:

<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>
name and Alias Use the custom domain name.
appBase and docBase Use the matching application context deployed under Tomcat’s webapps directory.

Example configuration for two domains:

<Host name="tomcatfirst.tk"
      appBase="webapps/tomcatfirst"
      autoDeploy="true">
    <Alias>tomcatfirst.tk</Alias>
    <Context path=""
             docBase="${catalina.base}/webapps/tomcatfirst"/>
</Host>

<Host name="tomcatsecond.tk"
      appBase="webapps/tomcatsecond"
      autoDeploy="true">
    <Alias>tomcatsecond.tk</Alias>
    <Context path=""
             docBase="${catalina.base}/webapps/tomcatsecond"/>
</Host>
Tomcat virtual-host configuration
Add one virtual-host definition for each domain and application context.
Configuration safety: Create a backup of server.xml before editing it. A malformed XML structure can prevent Tomcat from starting.

Restart and Test

8Save and restart Tomcat

Save server.xml and restart the Tomcat node or layer.

Restart Tomcat nodes
Restart Tomcat to apply the virtual-host configuration.

Open every custom domain in a browser. Each domain should load its assigned application from the same Tomcat server.

When HTTPS is required, configure an SSL certificate that covers every bound domain, or use separate certificates through the supported platform SSL workflow.

What’s next?