tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier ...@ice-sa.com>
Subject Re: Do multiple Hosts force multiple instances of webapps?
Date Tue, 07 Apr 2009 23:15:23 GMT
Ken Bowen wrote:
> [Feels like a newbie question, but I don't know the anwser.]
> 
> I have a web app (myapp) which has its context.xml in META-INF.
> 
> When I run it on a local vanilla Tomcat 6.0.18 (Apache download) with 
> the standard unzipped
> server.xml, only one instance of myapp is started (as observed in 
> catalina.out).
> 
> I have a Tomcat 6.0.18 running on a CentOS 5 Linux on a remote hosting 
> service.
> (Actually running in a Parallels virtual VPS.)
> That system has two hosts in the server.xml (set up by the remote 
> hosting service) as follows:
> 
>       <Host name="localhost"  appBase="webapps"
>             unpackWARs="true" autoDeploy="true"
>             xmlValidation="false" xmlNamespaceAware="false">
>       </Host>
> 
>       <Host appBase="webapps" name="mydomain.com" unpackWARs="true" 
> autoDeploy="true">
>           <Alias>www.mydomain.com</Alias>
>           <Alias>123.123.123.123</Alias>
>       </Host>
> 
> Note that they share the appBase.
> When I drop myapp.war in webapps, and observe catalina.out, I see that 
> it is started twice.
> I assume that this is the expected behavior?
> 
> And so then the question is:  In a remote hosting setting like this, 
> what is the purpose
> of the localhost Host: <Host name="localhost" ....>    Do I need this at 
> all?
> Maybe it was just cruft left lying around by the person who set things up?
> 
It is the standard server.xml setting, and normally it is enough, because...

The first <Host> defined is the "default host".  Any request that comes 
in to this server on a part on which Tomcat is listening, and whose 
"Host:" header does not match any other <Host name="..."> tag, will be 
handled by that default host.
In other words, if you have only that first <Host> tag, then it will 
handle all requests.

Because you have a second <Host> tag defined, now you have two (virtual) 
hosts. Your Host #2 now matches all requests for "mydomain.com", 
"www.mydomain.com" and "123.123.123.123".
Your first <Host> still matches all requests addresses to "localhost", 
and all the ones not matched by your Host #2.
(Because it is still the default host).

To make a longer story shorter, just do this :
- remove the second <Host>
- add 3 aliases to the first "localhost" Host :
 >           <Alias>www.mydomain.com</Alias>
 >           <Alias>123.123.123.123</Alias>
             <Alias>mydomain.com</Alias>





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message