Our go-to server for enterprise J2EE apps is Tomcat. Frequently, we come across the requirement of deploying multiple web applications on the same Tomcat and mapping different subdomains to each web app.
For example,
<pre>crm.mydomain.com to an app deployed in webapps/crm
mobilerp.mydomain.com to an app deployed in webapps/erp</pre>
We usually do this with the virtual host facility available in Tomcat.
<pre><Host name="crm" appBase="webapps">
<Context path="" docBase="crm/"/>
</Host>
<Host name="erp" appBase="webapps">
<Context path="" docBase="erp/"/>
</Host></pre>
We usually deploy Tomcat in a cluster in
Now, if you setup your DNS with the 2 subdomain entries, the subdomains will be forwarded to the appropriate web apps by Tomcat.
Apache mod_jk:
We usually deploy Tomcat in a cluster in production using Apache and mod_jk. We need to do the following for that:
<pre><VirtualHost crm.mydomain.com:80>
ServerName crm.mydomain.com
JkMount / tomcat
JkMount /* tomcat
</VirtualHost>
<VirtualHost erp.mydomain.com:80>
ServerName erp.mydomain.com
JkMount / tomcat
JkMount /* tomcat
</VirtualHost></pre>
Ofcourse this is http. For https, we do our usual SSL steps. Your worker.properties will look something like this:
<pre>worker.list= tomcat,status
worker.tomcat1.type=ajp13
worker.tomcat1.port=8009
worker.tomcat1.host=
worker.tomcat2.type=ajp13
worker.tomcat2.port=8009
worker.tomcat2.host=
worker.tomcat.type=lb
worker.tomcat.sticky_session = 1
worker.tomcat.balance_workers=tomcat1,tomcat2
worker.status.type=status</pre>
Note: If after all this configuration, all sub domain still get redirected to the default web app, make the following change,
<pre><Host name="crm.mydomain.com" appBase="webapps">
<Context path="" docBase="crm/"/>
</Host>
<Host name="erp.mydomain.com" appBase="webapps">
<Context path="" docBase="erp/"/>
</Host></pre>
This is because mod_jk will forward the domain name as is.
Streamline Your Enterprise Apps with Our Expertise!
Configuring multiple subdomains on Apache Tomcat can streamline your deployment process and enhance the accessibility of your web applications. By leveraging Tomcat’s virtual host feature and integrating it with Apache mod_jk, you can efficiently map different subdomains to distinct web applications, ensuring that requests are routed correctly and your applications are optimally deployed. Whether you’re dealing with HTTP or HTTPS, and whether you’re working with a single server or a clustered environment, following these best practices will help you maintain a robust and scalable setup.
If you’re finding these configurations complex or if you need assistance with your Tomcat setup, our expert team is ready to help. We specialize in deploying and optimizing enterprise applications, ensuring that your subdomain mappings and overall server configurations are executed flawlessly.
Ready to optimize your application deployment? Check out our application development capabilities to see how we can assist you in achieving optimal performance and reliability for your web applications.