Multiple Subdomains in Apache / Tomcat with mod_jk - Ideas2IT

Multiple Subdomains in Apache / Tomcat with mod_jk

Share This

Our goto server for Enterprise J2EE apps is Tomcat. Frequently we come across the requirement of deploying multiple web applications on the same Tomcat and map different subdomains to each web app.

For example,
<pre> to an app deployed in webapps/crm to an app deployed in webapps/erp</pre>

We usually do this with virtual host facility available in Tomcat.

<pre><Host name="crm" appBase="webapps">
    <Context path="" docBase="crm/"/>

<Host name="erp" appBase="webapps">
  <Context path="" docBase="erp/"/>

Now if you setup your DNS with the 2 subdomain entries, the sub-domains will be forwarded to the appropriate webapps 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:

    JkMount / tomcat
    JkMount /* tomcat

    JkMount / tomcat
    JkMount /* tomcat

Ofcourse this is http. For https we do our usual SSL steps. Your will look something like this:

<pre>worker.list= tomcat,status


worker.tomcat.sticky_session = 1


Note: If after all this configuration, all sub domain still get redirected to the default web app, make the following change,

<pre><Host name="" appBase="webapps">
   <Context path="" docBase="crm/"/>

<Host name="" appBase="webapps">
   <Context path="" docBase="erp/"/>

This is because mod_jk will forward the domain name as is.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get Instant Pricing Straight to Your Inbox

Let us know what your needs are and get a quote sent straight to your inbox.

Thank you for contacting us

Get Pricing Sent Straight to Your Inbox