Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One Tomcat instance for two domains and two webapps

Tags:

java

tomcat

dns

How can I configure Tomcat (in standalone mode, that is without Apache [*]) so that I can deploy it on one server and have it serve two different webapps, depending on the domain name requested?

What are the gotchas when doing that? Can you have SSL on both domains? If anyone here actually did it I'd be interested in answer to these questions as well as as much feedback as possible...

I found a blog entry describing such a setup, but it's for Tomcat 5.5:

<Engine defaultHost="domain1.com" name="Catalina">
    <Host name="domain1.com" appBase="/home/user1/domain1">
     <Alias>www.domain1.com</Alias>
     <Context path="" docBase="."/>
    </Host>
    <Host name="domain2.com" appBase="/home/user1/domain2">
     <Alias>www.domain2.com</Alias>
     <Context path="" docBase="."/>
    </Host>

http://iam-rakesh.blogspot.com/2009/10/hosting-multiple-domains-in-tomcat.html

Also, as of now I've got one webapp, ROOT.war, inside .../tomcat/webapps/

How would that work once I'd have two "roots", one root webapp for domain1.com and one root webapp for domain2.com? Where would the .war needs to be located?

like image 280
Cedric Martin Avatar asked Feb 24 '12 02:02

Cedric Martin


People also ask

How do I host multiple websites on one Tomcat server?

As shown above, to have multiple aliases you can add multiple 'Alias' tags for each domain alias name. Using 'Context' tag. A'Context' element represents a web application running inside a host. where each directory under 'webapps' directory of your tomcat is one context.

Can Tomcat host multiple applications?

In contrast to standalone applications, Tomcat is installed as a service that can manage multiple applications within the same application process, avoiding the need for a specific setup for each application.

What is webapps folder in Tomcat?

The webapps directory is where deployed applications reside in Tomcat. The webapps directory is the default deployment location, but this can be configured with the appBase attribute on the <Host> element.


1 Answers

The blog that you linked to basically shows how to do it. The one thing that you need to differently is to set the 'docBase' attribute differently for each host. The docBase is the location of war files for that host. With different docBases, you can have different root apps.

like image 170
GreyBeardedGeek Avatar answered Oct 23 '22 18:10

GreyBeardedGeek