How to configure Subdomain in Tomcat 7?


Before we jump to solution let me write search queries used by users to do same so they will also get the solution.

  • Configure subdomain in apache tomcat 7.
  • Configuring Virtual Hosts.
  • Configure subdomain in server.xml
  • Configure subdomain in DNS.
  • Configure subdomain for java.
  • Configure subdomain step by step.
  • Configure subdomain on www.eatj.com 

There is no perfect solution available to configure subdomain. I walk through 200-300 webpages and article to get the solution. I prefer the solution must be understandable. I'll show you how you can configure subdomain(s).

In this example we'll configure subdomain m.domain.com . You can also have your subdomain like a4apple.domain.com . [Note : subdomain name must be lower case you can't give subdomain name as M.domain.com So keep in mind it won't work.]

Step 1: You need to modify the server.xml file available in ${catalina.home}/conf/server.xml or tomcat_installation/conf/server.xml. All you need is append below line of code with in <Engine> Tag.
<Host appbase="webapps/ROOT/m" autodeploy="true" name="m.domain.com" unpackwars="true" xmlnamespaceaware="false" xmlvalidation="false">
<Context docbase="/usr/local/software/tomcat7/webapps/ROOT/m" path="" reloadable="true"></Context>
<Context antijarlocking="false" antiresourcelocking="false" docbase="/usr/local/software/tomcat7/webapps/manager" path="/manager" privileged="true" reloadable="true"></Context>
</Host>
Things you need to change:

  • appbase : If you have folder where webapps folder is created then appbase will be just m . If folder is with in webapps then appbase will be webapps/m and so on...
  • name : change it with your domain name.
  • docbase in first context : Set the location of your folder with absolute path.
  • Second context : You can remove if you want or set it the the manager folder for your application.

Step 2: Edit DNS record for your website. Search for DNS editor on your website's admin panel. Follow below steps.

  • Go to List zones.
  • Edit your zones.
  • Add record.
  • Provide name m.domain.com
  • Set Type to A
  • Set Content to your Server IP Address.
  • Set TTL as per your want or 86400.

Note 1: DNS changes may take sometime if you are working on shared server or ask to your hosting provider.
Note 2: If you are working on windows then search on www.google.com for edit hosts file for subdomain .

Step 3: Restart your Apache Tomcat 7.

0 comments :

Note: only a member of this blog may post a comment.