tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier>
Subject Re: Do multiple Hosts force multiple instances of webapps?
Date Tue, 07 Apr 2009 23:18:26 GMT
André Warnier wrote:
> 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="" unpackWARs="true" 
>> autoDeploy="true">
>>           <Alias></Alias>
>>           <Alias></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 "", 
> "" and "".
> 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></Alias>
>  >           <Alias></Alias>
>             <Alias></Alias>
Of course, as Charles pointed out, these 3 aliases are totally 
superfluous, for the reason I myself outlined above. Duh..
Time to go to bed here too.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message