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 Jelastic 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, multibinding.
In a minute your environment will be successfully created.
3. 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 Jelastic dashboard, click the Settings button for your environment and bind your domains.
In our example, we’ll use tomcatfirst.tk for the first domain name, and tomcatsecond.tk for the second.
5. Now you need to deploy the projects.
When the Deploy form appears choose your environment and assign the context (tomcatfirst, in our case). Then press Deploy button.
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:
<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>
In our sample, we add the following code to server.xml file:
<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>
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 afterwards.
Powered by BetterDocs
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.