You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ken Bowen <kb...@als.com> on 2009/04/08 00:59:27 UTC
Do multiple Hosts force multiple instances of webapps?
[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?
I certainly want to avoid two copies of myapp running.
Thanks in advance
Ken
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Do multiple Hosts force multiple instances of webapps?
Posted by André Warnier <aw...@ice-sa.com>.
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="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>
>
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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Do multiple Hosts force multiple instances of webapps?
Posted by Ken Bowen <kb...@als.com>.
Thanks! To both Chuck & Andre.
Not only does the simple solution work, but I understand a tiny bit
more.
Have a good night.
Ken
On Apr 7, 2009, at 7:20 PM, Caldarale, Charles R wrote:
>> From: André Warnier [mailto:aw@ice-sa.com]
>> Subject: Re: Do multiple Hosts force multiple instances of webapps?
>>
>> The first <Host> defined is the "default host".
>
> No - the defaultHost is the defined by the defaultHost attribute of
> the <Engine>. It can be any of the <Host> elements.
>
>> 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>
>
> Or, just use one <Host> and no aliases. What you're suggesting is
> unnecessarily complex and serves no real purpose.
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE
> PROPRIETARY MATERIAL and is thus for use only by the intended
> recipient. If you received this in error, please contact the sender
> and delete the e-mail and its attachments from all computers.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Do multiple Hosts force multiple instances of webapps?
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: André Warnier [mailto:aw@ice-sa.com]
> Subject: Re: Do multiple Hosts force multiple instances of webapps?
>
> The first <Host> defined is the "default host".
No - the defaultHost is the defined by the defaultHost attribute of the <Engine>. It can be any of the <Host> elements.
> 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>
Or, just use one <Host> and no aliases. What you're suggesting is unnecessarily complex and serves no real purpose.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Do multiple Hosts force multiple instances of webapps?
Posted by André Warnier <aw...@ice-sa.com>.
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
RE: Do multiple Hosts force multiple instances of webapps?
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Ken Bowen [mailto:kbowen@als.com]
> Subject: Do multiple Hosts force multiple instances of webapps?
> Note that they share the appBase.
Which can lead to "interesting" events when updating on the fly.
> 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?
Yes; there's a separate classloader created for each <Host>/<Context> combination.
> And so then the question is: In a remote hosting setting
> like this, what is the purpose of the localhost Host:
> <Host name="localhost" ....>
You might well ask what's the purpose of the other <Host> with the domain name. You really only need one, and its name is irrelevant, as long as that name appears on the defaultHost attribute of the <Engine>.
Multiple <Host> elements are useful when you really are serving separate, multiple domains.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org