Multiple Domains for Tomcat
Multiple Domain Names on Tomcat Server
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.
2Select Tomcat
Choose a Tomcat application server, configure the required resources, enter an environment name such as multibinding, and create the environment.
After provisioning completes, the Tomcat environment appears in the dashboard.
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.
4Bind each domain
Enter the first custom domain, click Bind, and repeat the process for the remaining domains.
Deploy the Applications
5Upload the first application
Add the application archive to Deployment Manager and click Deploy to….
Select the Tomcat environment and assign a unique context, for example tomcatfirst.
6Deploy the second application
Upload the second archive and deploy it to the same environment with a different context, such as tomcatsecond.
After deployment, both contexts should appear under the application-server layer.
Configure Tomcat Virtual Hosts
7Open server.xml
Click Config for the Tomcat layer and open /opt/tomcat/conf/server.xml.
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>
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.
Open every custom domain in a browser. Each domain should load its assigned application from the same Tomcat server.
