Wednesday, September 5, 2012

Configuring multiple domains or sub-domains in tomcat

Sponsored Links

We all know how to create multiple domains in Apache. By adding virtual host etries. But how to configure multiple domains in tomcat? We can do this by adding multiple Host tags in server.xml. Its very simple. See the example below. Edit server.xml under conf directory. Suppose you want to setup three domains domain1.com, domain2.com and domain3.com. Every domain points to same ip address in the server.

<Engine defaultHost="arnid" name="Catalina">
<Host name="domain1.com" appBase="/usr/tomcat/apache-tomcat-6.0.26/webapps/domain_root1">
        unpackWARs="true" autoDeploy="true"
        <Alias>www.domain1.com</Alias>
        <Context path="" docBase="."/>
</Host>
<Host name="domain2.com" appBase="/usr/tomcat/apache-tomcat-6.0.26/webapps/domain_root2">
        unpackWARs="true" autoDeploy="true"
        <Alias>www.domain2.com</Alias>
        <Context path="" docBase="."/>
</Host>
<Host name="domain3.com" appBase="/usr/tomcat/apache-tomcat-6.0.26/webapps/domain_root3">
        unpackWARs="true" autoDeploy="true"
        <Alias>www.domain3.com</Alias>
        <Context path="" docBase="."/>
</Host>
<Engine
Now restart tomcat and everything should be working fine.


Recommended Reading

1. Web Application Architecture: Principles, Protocols and Practices
2. The Accidental Administrator: Linux Server Step-by-Step Configuration Guide
3. Apache Tomcat 7
4. Run Your Own Web Server Using Linux & Apache
5. Professional Apache Tomcat 6 (WROX Professional Guides)
6. Web Server Administration (Web Warrior)

Sponsored Links

No comments:

Post a Comment

Be nice. That's all.