You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paul van Hoven <pa...@googlemail.com> on 2012/11/22 00:08:55 UTC

Tomcat with multiple domains

Hi!

I'm trying to setup virtual hosts for my single tomcat webserver. I've
got the following setup: Apache Tomcat 7.0.32 running on a server with
one IP address. I forward any requests coming in on port 80 to port
8080 and from 443 to 8443 with a firewall rule. I have 2 domains and I
would like to run these two domains on the same Tomcat machine.
Therefore I had a look at the virtual host concept.

I found the following tutorial (very old) on the web:
http://onjava.com/pub/a/onjava/2006/08/30/publishing-multiple-sites-using-single-tomcat.html

and I payed attention to the offical Tomcat documentation in regard of this:
http://tomcat.apache.org/tomcat-7.0-doc/virtual-hosting-howto.html

So I made the following:
1. In my $CATALINA_HOME (which is /opt/apache-tomcat-7.0.32) I created
the folder "my2ndDomain"

2. Then I copied the war file I'd like to deploy into the folder and
renamed it. Such that now I have the following file in my folder
/opt/apache-tomcat-7.0.32/my2ndDomain/ROOT.war

3. Then I modified my "/opt/apache-tomcat-7.0.32/conf/server.xml" the
following way:
        <Host name="localhost"  appBase="webapps" unpackWARs="true"
autoDeploy="true">
        <Host name="wettprofi" appBase="my2ndDomain" unpackWARs="true"
autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
                <Alias>my2ndDomain.com</Alias>
                <Alias>www.my2ndDomain.com</Alias>
                <Context path="my2ndDomain" debug="0" reloadable="false"/>
        </Host>
4. I restarted my Tomcat but nothing happened, entering
www.my2ndDomain.com was routed to the standard first domain running.

I'm wondering what I am doing wrong here.

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


Re: Tomcat with multiple domains

Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/11/28 Paul van Hoven <pa...@googlemail.com>:
>
> I edited the /etc/hosts file and added the following entries:
> 88.84.140.88    www.2nddomain.com:8080
> 88.84.140.88    www.1rstdomain.com:8080

Domain Name Service resolves host names.  A port number is not part of
a host name. The above two lines are invalid.

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


Re: Tomcat with multiple domains

Posted by André Warnier <aw...@ice-sa.com>.
Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> André,
> 
> On 11/30/12 10:11 AM, André Warnier wrote:
>> Jeffrey Janner wrote:
>>>> -----Original Message----- From: Paul van Hoven
>>>> [mailto:paul.van.hoven@googlemail.com] Sent: Wednesday,
>>>> November 28, 2012 5:29 PM To: Tomcat Users List Subject: Re:
>>>> Tomcat with multiple domains
>>>>
>>>> Hi!
>>>>
>>>> Thanks for your quick and detailed answers. Actually I think I
>>>> did all the things you mentioned but it still does not work. So
>>>> here are the changes I made:
>>>>
>>>> 1. I checked that the following entries are in the engine tag: 
>>>> <Server port="8005" shutdown="SHUTDOWN"> ... <Service
>>>> name="Catalina"> ... <Engine name="Catalina"
>>>> defaultHost="localhost"> <Host name="localhost" 
>>>> appBase="webapps" unpackWARs="true" autoDeploy="true">
>>> [Jeff Janner] You need a "</Host>" here.  All elements must have
>>> a begin tag and an end tag! If there are no sub-elements, you can
>>> combine the begin and end tags as <tagname ... />. Please find a
>>> good introductory reference on XML markup language before
>>> continuing.
>>>
>>>> <Host name="www.my2nddomain.com" 
>>>> appBase="/opt/apache-tomcat-7.0.32/my2nddomain"
>>>> unpackWARs="true" autoDeploy="true" xmlValidation="false"
>>>> xmlNamespaceAware="false"> </Host>
>> Haaa. Good catch, Jeffrey. Everyone else missed that.
> 
> +1
> 
>> So it probably "swallowed" the second Host's tags in the first,
>> with who knows which results. Surprising that Tomcat still starts.
> 
> Unfortunately, Tomcat does not validate against an XML schema or DTD
> and so otherwise insane configurations can generally be launched
> without any errors being generated.
> 
> This is a double-edged sword. In this case, it made it difficult to
> detect a configuration error. In other cases, it makes it possible to
> use very complex configuration that the Tomcat developers didn't
> expect beforehand.
> 
> One reason Tomcat cannot validate against a schema or DTD is because
> of things like <Resource>: they allow a user to specify any attribute
> name and have its value get set on the component being configured.
> This is not possible with a strictly-validating parser.
> 
> I'm unaware of a technique to allow partial structural validity (say,
> element nesting) without also explicitly specifying which attributes
> are allowed.
> 
> Use of the Apache commons-digester component means that detecting
> structural missteps would require that the component be configured
> with all possible missteps in advance which is quite impossible.
> 
> I haven't looked, but it might be nice if the digester supported
> fallback rules where an event that didn't match an existing rule could
> fire a catch-all rule. That way, an unexpected element could generate
> an error message and possibly prevent Tomcat from even starting.
> 

I wasn't complaining or criticising, just wondering.
It isn't so easy to compose an XML document, miss a closing tag and still having it be 
valid XML.
If you go back the the OP's last post and the described symptoms, and assume that he did 
describe accurately what happened, it means that the missing </Host> tag had some really 
interesting effects.

What we really need on this user list, is an interactive XML parser where we can check 
configuration snippets posted by users.
(one which would of course first and automatically get rid of all the email artifacts, 
in-between comments etc.)

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


Re: Tomcat with multiple domains

Posted by André Warnier <aw...@ice-sa.com>.
Paul, you shouldn't top-post.  It makes it hard to follow the logical gist of the 
conversation.

> 
> 2012/11/30 Hassan Schroeder <ha...@gmail.com>:
>> On Fri, Nov 30, 2012 at 2:12 PM, Christopher Schultz
>> <ch...@christopherschultz.net> wrote:
>>
>>> OP never posted the whole XML, so we don't know that it's definitely
>>> not well-formed.
>> Good point -- should have asked for the whole file before jumping to
>> that conclusion. But it certainly looked sketchy :-)
>>
>> --
Paul van Hoven wrote:
 > Thank you guys for your great help. It was indeed an error in the xml
 > that I entered in the server.xml file. I put something like this:
 >
 > <Server port="8005" shutdown="SHUTDOWN">
 > ...
 > <Service name="Catalina">
 > ...
 > <Engine name="Catalina" defaultHost="localhost">
 > <Host name="localhost"  appBase="webapps"
 >             unpackWARs="true" autoDeploy="true">
 > <Host name="www.my2nddomain.com"
 > appBase="/opt/apache-tomcat-7.0.32/my2nddomain" unpackWARs="true"
 > autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
 >         </Host>
 >    </Host>
 > </Engine>
 >   </Service>
 > </Server>
 >
 > Notice that I nested the virtual host definition within the host
 > definition tags of the default host. So, therefore it did not work and
 > I didn't see it.
 >
 > Okay now it works perfectly fine. Again, thanks for your fantastic support!

So, taking into account Christoper's detailed explanation of why Tomcat would not detect 
this as an error in server.xml, we are still left with something strange here.

Assuming that Paul previously reported the result correctly (he requested a URL mapping to 
the first host, and got a response from an app of the second Host instead), that would 
mean that in the process of parsing the above, Tomcat somehow overwrote the appBase of the 
first <Host> tag, with the appBase of the second <Host> tag, no ?



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


Re: Tomcat with multiple domains

Posted by Paul van Hoven <pa...@googlemail.com>.
Thank you guys for your great help. It was indeed an error in the xml
that I entered in the server.xml file. I put something like this:

<Server port="8005" shutdown="SHUTDOWN">
...
<Service name="Catalina">
...
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
<Host name="www.my2nddomain.com"
appBase="/opt/apache-tomcat-7.0.32/my2nddomain" unpackWARs="true"
autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
        </Host>
   </Host>
</Engine>
  </Service>
</Server>

Notice that I nested the virtual host definition within the host
definition tags of the default host. So, therefore it did not work and
I didn't see it.

Okay now it works perfectly fine. Again, thanks for your fantastic support!

2012/11/30 Hassan Schroeder <ha...@gmail.com>:
> On Fri, Nov 30, 2012 at 2:12 PM, Christopher Schultz
> <ch...@christopherschultz.net> wrote:
>
>> OP never posted the whole XML, so we don't know that it's definitely
>> not well-formed.
>
> Good point -- should have asked for the whole file before jumping to
> that conclusion. But it certainly looked sketchy :-)
>
> --
> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
> http://about.me/hassanschroeder
> twitter: @hassan
>
> ---------------------------------------------------------------------
> 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: Tomcat with multiple domains

Posted by Hassan Schroeder <ha...@gmail.com>.
On Fri, Nov 30, 2012 at 2:12 PM, Christopher Schultz
<ch...@christopherschultz.net> wrote:

> OP never posted the whole XML, so we don't know that it's definitely
> not well-formed.

Good point -- should have asked for the whole file before jumping to
that conclusion. But it certainly looked sketchy :-)

-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

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


Re: Tomcat with multiple domains

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hassan,

On 11/30/12 5:04 PM, Hassan Schroeder wrote:
> On Fri, Nov 30, 2012 at 1:50 PM, Christopher Schultz 
> <ch...@christopherschultz.net> wrote:
> 
>> I'm unaware of a technique to allow partial structural validity
>> (say, element nesting) without also explicitly specifying which
>> attributes are allowed.
> 
> Wait, what? The OP's example isn't even well-formed XML, and any 
> decent text editor should flag that.
> 
> Attribute names and values aren't relevant to well-formed-ness.

OP never posted the whole XML, so we don't know that it's definitely
not well-formed.

Tomcat definitely bombs if the document isn't well-formed:

Nov 30, 2012 5:08:28 PM org.apache.tomcat.util.digester.Digester
endElement
WARNING:   No rules found matching 'Server/Service/Engine/Host/Host'.
Nov 30, 2012 5:08:28 PM org.apache.tomcat.util.digester.Digester
fatalError
SEVERE: Parse Fatal Error at line 152 column 7: The element type
"Host" must be terminated by the matching end-tag "</Host>".
org.xml.sax.SAXParseException; systemId:
file:/CATALINA_BASE/conf/server.xml; lineNumber: 152; columnNumber: 7;
The element type "Host" must be terminated by the matching end-tag
"</Host>".
        at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAX
ParseException(ErrorHandlerWrapper.java:198)
  [....]

If the OP was using an XML editor (again, without any Schema or DTD),
it might have let him (or even auto-fixed the structure to) do this:

<Service>
 <Engine>
  <Host>
   <Host>
   </Host>
  </Host>
 </Engine>
</Service>

This message would have showed up in catalina.out:

Nov 30, 2012 5:11:47 PM org.apache.tomcat.util.digester.Digester
endElement
WARNING:   No rules found matching 'Server/Service/Engine/Host/Host'.

...but such a thing is easy to miss.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with undefined - http://www.enigmail.net/

iEYEARECAAYFAlC5L2sACgkQ9CaO5/Lv0PD/1wCgpJIRrwYORoDhSZaxYOx2cG2Z
/VgAoLd0WLVjOwohYT+gC1z+AEIq2mTT
=kDgf
-----END PGP SIGNATURE-----

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


Re: Tomcat with multiple domains

Posted by Hassan Schroeder <ha...@gmail.com>.
On Fri, Nov 30, 2012 at 1:50 PM, Christopher Schultz
<ch...@christopherschultz.net> wrote:

> I'm unaware of a technique to allow partial structural validity (say,
> element nesting) without also explicitly specifying which attributes
> are allowed.

Wait, what? The OP's example isn't even well-formed XML, and any
decent text editor should flag that.

Attribute names and values aren't relevant to well-formed-ness.

-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

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


Re: Tomcat with multiple domains

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

André,

On 11/30/12 10:11 AM, André Warnier wrote:
> Jeffrey Janner wrote:
>>> -----Original Message----- From: Paul van Hoven
>>> [mailto:paul.van.hoven@googlemail.com] Sent: Wednesday,
>>> November 28, 2012 5:29 PM To: Tomcat Users List Subject: Re:
>>> Tomcat with multiple domains
>>> 
>>> Hi!
>>> 
>>> Thanks for your quick and detailed answers. Actually I think I
>>> did all the things you mentioned but it still does not work. So
>>> here are the changes I made:
>>> 
>>> 1. I checked that the following entries are in the engine tag: 
>>> <Server port="8005" shutdown="SHUTDOWN"> ... <Service
>>> name="Catalina"> ... <Engine name="Catalina"
>>> defaultHost="localhost"> <Host name="localhost" 
>>> appBase="webapps" unpackWARs="true" autoDeploy="true">
>> 
>> [Jeff Janner] You need a "</Host>" here.  All elements must have
>> a begin tag and an end tag! If there are no sub-elements, you can
>> combine the begin and end tags as <tagname ... />. Please find a
>> good introductory reference on XML markup language before
>> continuing.
>> 
>>> <Host name="www.my2nddomain.com" 
>>> appBase="/opt/apache-tomcat-7.0.32/my2nddomain"
>>> unpackWARs="true" autoDeploy="true" xmlValidation="false"
>>> xmlNamespaceAware="false"> </Host>
> 
> Haaa. Good catch, Jeffrey. Everyone else missed that.

+1

> So it probably "swallowed" the second Host's tags in the first,
> with who knows which results. Surprising that Tomcat still starts.

Unfortunately, Tomcat does not validate against an XML schema or DTD
and so otherwise insane configurations can generally be launched
without any errors being generated.

This is a double-edged sword. In this case, it made it difficult to
detect a configuration error. In other cases, it makes it possible to
use very complex configuration that the Tomcat developers didn't
expect beforehand.

One reason Tomcat cannot validate against a schema or DTD is because
of things like <Resource>: they allow a user to specify any attribute
name and have its value get set on the component being configured.
This is not possible with a strictly-validating parser.

I'm unaware of a technique to allow partial structural validity (say,
element nesting) without also explicitly specifying which attributes
are allowed.

Use of the Apache commons-digester component means that detecting
structural missteps would require that the component be configured
with all possible missteps in advance which is quite impossible.

I haven't looked, but it might be nice if the digester supported
fallback rules where an event that didn't match an existing rule could
fire a catch-all rule. That way, an unexpected element could generate
an error message and possibly prevent Tomcat from even starting.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with undefined - http://www.enigmail.net/

iEYEARECAAYFAlC5KjQACgkQ9CaO5/Lv0PBR4wCgijyZWhQEcknzui7Dm6CUwnTY
x+kAoLXjE9IsomYVwhp9hNgoBDYgx3Ek
=OmWc
-----END PGP SIGNATURE-----

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


RE: Tomcat with multiple domains

Posted by Jeffrey Janner <Je...@PolyDyne.com>.
> -----Original Message-----
> From: André Warnier [mailto:aw@ice-sa.com]
> Sent: Friday, November 30, 2012 9:11 AM
> To: Tomcat Users List
> Subject: Re: Tomcat with multiple domains
> 
> Jeffrey Janner wrote:
> >> -----Original Message-----
> >> From: Paul van Hoven [mailto:paul.van.hoven@googlemail.com]
> >> Sent: Wednesday, November 28, 2012 5:29 PM
> >> To: Tomcat Users List
> >> Subject: Re: Tomcat with multiple domains
> >>
> >> Hi!
> >>
> >> Thanks for your quick and detailed answers. Actually I think I did
> >> all the things you mentioned but it still does not work. So here are
> >> the changes I made:
> >>
> >> 1. I checked that the following entries are in the engine tag:
> >> <Server port="8005" shutdown="SHUTDOWN"> ...
> >> <Service name="Catalina">
> >> ...
> >> <Engine name="Catalina" defaultHost="localhost"> <Host
> name="localhost"
> >> appBase="webapps"
> >>             unpackWARs="true" autoDeploy="true">
> >
> >  [Jeff Janner] You need a "</Host>" here.  All elements must have a
> begin tag and an end tag!
> >                If there are no sub-elements, you can combine the
> begin and end tags as <tagname ... />.
> >                Please find a good introductory reference on XML
> markup language before continuing.
> >
> >> <Host
> >> name="www.my2nddomain.com"
> >> appBase="/opt/apache-tomcat-7.0.32/my2nddomain" unpackWARs="true"
> >> autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
> >> 	</Host>
> 
> Haaa. Good catch, Jeffrey. Everyone else missed that.
> So it probably "swallowed" the second Host's tags in the first, with
> who knows which results.
> Surprising that Tomcat still starts.

You wouldn't believe how any times I've had to correct something like this for customer self-installs, even with what I think is proper documentation to guide them.
It really does come down to understanding the structure of XML.
Jeff


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


Re: Tomcat with multiple domains

Posted by André Warnier <aw...@ice-sa.com>.
Jeffrey Janner wrote:
>> -----Original Message-----
>> From: Paul van Hoven [mailto:paul.van.hoven@googlemail.com]
>> Sent: Wednesday, November 28, 2012 5:29 PM
>> To: Tomcat Users List
>> Subject: Re: Tomcat with multiple domains
>>
>> Hi!
>>
>> Thanks for your quick and detailed answers. Actually I think I did all
>> the things you mentioned but it still does not work. So here are the
>> changes I made:
>>
>> 1. I checked that the following entries are in the engine tag:
>> <Server port="8005" shutdown="SHUTDOWN"> ...
>> <Service name="Catalina">
>> ...
>> <Engine name="Catalina" defaultHost="localhost"> <Host name="localhost"
>> appBase="webapps"
>>             unpackWARs="true" autoDeploy="true">
> 
>  [Jeff Janner] You need a "</Host>" here.  All elements must have a begin tag and an end tag!
>                If there are no sub-elements, you can combine the begin and end tags as <tagname ... />.
>                Please find a good introductory reference on XML markup language before continuing.
> 
>> <Host
>> name="www.my2nddomain.com"
>> appBase="/opt/apache-tomcat-7.0.32/my2nddomain" unpackWARs="true"
>> autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
>> 	</Host>

Haaa. Good catch, Jeffrey. Everyone else missed that.
So it probably "swallowed" the second Host's tags in the first, with who knows which results.
Surprising that Tomcat still starts.


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


RE: Tomcat with multiple domains

Posted by Jeffrey Janner <Je...@PolyDyne.com>.
> -----Original Message-----
> From: Paul van Hoven [mailto:paul.van.hoven@googlemail.com]
> Sent: Wednesday, November 28, 2012 5:29 PM
> To: Tomcat Users List
> Subject: Re: Tomcat with multiple domains
> 
> Hi!
> 
> Thanks for your quick and detailed answers. Actually I think I did all
> the things you mentioned but it still does not work. So here are the
> changes I made:
> 
> 1. I checked that the following entries are in the engine tag:
> <Server port="8005" shutdown="SHUTDOWN"> ...
> <Service name="Catalina">
> ...
> <Engine name="Catalina" defaultHost="localhost"> <Host name="localhost"
> appBase="webapps"
>             unpackWARs="true" autoDeploy="true">

 [Jeff Janner] You need a "</Host>" here.  All elements must have a begin tag and an end tag!
               If there are no sub-elements, you can combine the begin and end tags as <tagname ... />.
               Please find a good introductory reference on XML markup language before continuing.

> <Host
> name="www.my2nddomain.com"
> appBase="/opt/apache-tomcat-7.0.32/my2nddomain" unpackWARs="true"
> autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
> 	</Host>
> </Engine>
>   </Service>
> </Server>
> 
> 2. In the host file I altered the entries to
> 88.84.140.85	www.my2nddomain.com
> 88.84.140.85	www.my1rstdomain.com
> 
> 3. I actually did not really understand what you meant by
> > Also, since you are using the /etc/hosts file instead of the DNS
> system, the client (browser) also has those entries in its hosts file.
> And, as Konstantin pointed out, you don't put the port number in the
> /etc/hosts file.
> > If you are using DNS for the clients, make sure that it has entries
> for both hosts, pointing to the same IP address.
> 
> I'm not shure if I understand the meaning of DNS in this case
> correctly. Do you mean a DNS on my local machine or do you mean the DNS
> on a remote machine? I've got a pure domain hoster and I set an A
> record entry such that the domain is forwarded to my server / ip
> address 88.84.140.85. Both domains are actually pointing to this ip
> address since both are hosted by the same domain hoster. I do not
> explicitly use DNS on my local machine, at least I did not configure
> it.
> 
> And how can the client (browser) have entries in a host file?
> 
> 
> The current status is that when calling www.my1rstdomain.com:8080
> points to the webapp installed for www.my2nddomain.com:8080.
> 
> 
> 2012/11/27 Jeffrey Janner <Je...@polydyne.com>:
> >> -----Original Message-----
> >> From: Paul van Hoven [mailto:paul.van.hoven@googlemail.com]
> >> Sent: Tuesday, November 27, 2012 2:13 PM
> >> To: Tomcat Users List
> >> Subject: Re: Tomcat with multiple domains
> >>
> >> Thanks for the answer. I followed the tutorial you propose (
> >> http://wiki.apache.org/tomcat/TomcatDevelopmentVirtualHosts ). But
> it
> >> is still not working. Here is my new configuration
> >>
> >>
> >> server.xml
> >> <Host name="2nddomain.com"
> >> appBase="/opt/apache-tomcat-7.0.32/2nddomain.com" unpackWARs="true"
> >> autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
> >>               <Alias>2nddomain.com</Alias>
> >>               <Alias>www.2nddomain.com</Alias>
> >>       </Host>
> >>
> >> The directory
> >> /opt/apache-tomcat-7.0.32/2nddomain.com
> >> contains a ROOT.war file.
> >>
> >> I edited the /etc/hosts file and added the following entries:
> >> 88.84.140.88  www.2nddomain.com:8080
> >> 88.84.140.88  www.1rstdomain.com:8080
> >>
> >> Then I restarted the system and the tomcat server. Entering
> >> www.2nddomain.com:8080 sends me to 1rstdomain.com. I noticed that
> the
> >> file  "/opt/apache-tomcat-7.0.32/2nddomain.com/ROOT.war" remains
> >> untouched by tomcat, at least nothing is extracted from the war
> file.
> >>
> >> So what else am I missing here?
> >
> > Make sure that the new <Host></Host> definition is nested inside the
> <Engine></Engine> tags.
> > You also do not need the first <Alias> line.  The name= parameter
> takes care of that mapping for you.
> > In general, the nesting works this way:
> > <Server ... >
> >   <Service ... >
> >     <Connector ... />
> >     <Connector ... />
> >     <Engine ... >
> >       <Host name="host1.com" ... >
> >         <Alias>www.host1.com</Alias>
> >       </Host>
> >       <Host name="www.host2.com" ... >
> >         <Alias>host2.com</Alias>
> >       </Host>
> >       <Host name="www.myhost.com" ... />
> >     </Engine>
> >   </Service>
> > </Server>
> >
> > There are a myriad other tag sets that could be included in there and
> it's very important that they be nested properly to work properly.
> >
> > Also, since you are using the /etc/hosts file instead of the DNS
> system, the client (browser) also has those entries in its hosts file.
> And, as Konstantin pointed out, you don't put the port number in the
> /etc/hosts file.
> > If you are using DNS for the clients, make sure that it has entries
> for both hosts, pointing to the same IP address.
> >
> >
> > ---------------------------------------------------------------------
> > 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
> 



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


Re: Tomcat with multiple domains

Posted by André Warnier <aw...@ice-sa.com>.
Hi.

Here is a brief tutorial on how the "virtual host thing" works.
(I find that many times, reminding someone of these basic things helps in diagnosing 
things quickly).

1) the browser is given a URL to retrieve, say "http://myhost.mycompany.com:8080/home.html"

2) the browser parses this URL in :
protocol : http
hostname : myhost.mycompany.com
port : 8080
URI : /home.html
(note : if the port is not given, it becomes the default for the protocol; for example, 
for http this would be 80, and for https it would be 443)

2) the browser first asks it's local O.S. "resolver", to translate the hostname into an IP 
address.
The resolver is the part of the OS which does these translations, and usually
- it first looks at the local "hosts" file, to find a name-to-address translation
(under Unix/Linux, this is /etc/hosts; under Windows, it is usually 
(windows_dir)/system32/drivers/etc/hosts )
- if it is not in the local hosts file, it will contact a "DNS server" host, and ask it to 
tranalate the address.
In a LAN, the DNS host is usually a local DNS server system.  Otherwise, it is a DNS 
server on the Internet.
(Note: DNS stands for "Domain Name System" and is a standard feature on the Internet)

3) if the browser could not get a name-to-address translation, it will print an error 
message "host 'myhost.mycompany.com' could not be found".
If the browser received an IP address from the resolver, it "believes" it unconditionally, 
even if it happens to be false, and goes to the next step.

4) the browser establishes a TCP connection to the obtained IP address, and the port 
determined from the URL.
If the browser cannot establish this connection, it will print an error message "host 
'myhost.mycompany.com' is not responding - try again later".

(Note: if you get this far, it means at least that the hostname was translated to an IP 
address in some way. It does not mean that the IP address is correct, but it's a start.)

5) on this established TCP connection, the browser sends a HTTP request, consisting of 
several lines, as a minimum the following 2 lines :
GET /home.html HTTP/1.1
Host: myhost.mycompany.com
..

6) at the receiving end, it is assumed that a webserver has accepted the TCP connection, 
and is reading what the browser sends on it.  It thus reads the request, as a minimum the 
same 2 lines :
GET /home.html HTTP/1.1
Host: myhost.mycompany.com

7) the webserver parses the HTTP request headers, in particular the "Host:" header.
This tells it the name of the "virtual host" to which this request is addressed.

8) the webserver looks through it's own list of virtual hosts, to find one of which either 
the "hostname" or an "alias" matches the "Host:" header exactly.

9) If the webserver finds such a virtual host, then it sets itself up so that this request 
is handled according to the configuration of that virtual host.

10) If the webserver does not find such a virtual host (neither hostname nor alias match 
any defined virtual host), then it will direct the request to its "default virtual host".
This varies a bit from webserver to webserver, but
- for Tomcat it is the Host named in the Engine tag
- for Apache httpd, it is the first VirtualHost named in the httpd configuration

Now, I suggest that you go through the above steps, one by one, really thinking about what 
happens and if it happens, and make sure that you eliminate all the possibilities that do 
not apply.
And as Sherlock Holmes would say, once you have eliminated all the unlikely things, what 
remains, even if it is impossible, must be the truth.

In your case, according to your last post, you send a request with a URL of "http:// 
www.my1rstdomain.com:8080", and you say that the webapp which answers is started in the 
Host with hostname "www.my2nddomain.com".
That does /not/ make sense according to the above scenario.
So either you are not showing us your real configuration, or you have not restarted Tomcat 
after making configuration changes, or you are not describing accurately what you are doing.
Check again.



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


Re: Tomcat with multiple domains

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Paul,

On 11/28/12 6:29 PM, Paul van Hoven wrote:
> Thanks for your quick and detailed answers. Actually I think I did
> all the things you mentioned but it still does not work. So here
> are the changes I made:
> 
> 1. I checked that the following entries are in the engine tag: 
> <Server port="8005" shutdown="SHUTDOWN"> ... <Service
> name="Catalina"> ... <Engine name="Catalina"
> defaultHost="localhost"> <Host name="localhost"  appBase="webapps" 
> unpackWARs="true" autoDeploy="true"> <Host
> name="www.my2nddomain.com" 
> appBase="/opt/apache-tomcat-7.0.32/my2nddomain" unpackWARs="true" 
> autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> 
> </Host> </Engine> </Service> </Server>

This looks correct to me.

> 2. In the host file I altered the entries to 88.84.140.85
> www.my2nddomain.com 88.84.140.85	www.my1rstdomain.com

Is this on the server or the client? Or both?

Go to the machine you are using as an HTTP client (e.g. web browser)
and type this on the command line:

nslookup www.my2nddomain.com

You should get 88.84.140.85 back.

Next, you need to make sure that the client is sending a "Host" header
with the HTTP message. The Host header is required for HTTP/1.1, so if
the client is not specifying the Host, it is non-compliant.

Tomcat can't determine the virtual host to use if the Host header is
absent. If the Host header is absent or the value of Host does not
match anything Tomcat has configured, the default Host for the Engine
will be used. In your case, it's the "localhost" host.

> The current status is that when calling www.my1rstdomain.com:8080 
> points to the webapp installed for www.my2nddomain.com:8080.

That seems very odd, since you don't have any configuration for
www.my1rstdomain.com, so you should get the default. What happens when
you request www.my2nddomain.com?

Can you post an HTTP protocol trace of a request/response?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with undefined - http://www.enigmail.net/

iEYEARECAAYFAlC35rMACgkQ9CaO5/Lv0PBg7wCfbZ5FAYwfrCQfx0vb1KjB3j/2
QxwAnjFvdrNhV+XhxQ+ttDDpOiaJtp3d
=EUkh
-----END PGP SIGNATURE-----

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


Re: Tomcat with multiple domains

Posted by Paul van Hoven <pa...@googlemail.com>.
Hi!

Thanks for your quick and detailed answers. Actually I think I did all
the things you mentioned but it still does not work. So here are the
changes I made:

1. I checked that the following entries are in the engine tag:
<Server port="8005" shutdown="SHUTDOWN">
...
<Service name="Catalina">
...
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
<Host name="www.my2nddomain.com"
appBase="/opt/apache-tomcat-7.0.32/my2nddomain" unpackWARs="true"
autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
	</Host>
</Engine>
  </Service>
</Server>

2. In the host file I altered the entries to
88.84.140.85	www.my2nddomain.com
88.84.140.85	www.my1rstdomain.com

3. I actually did not really understand what you meant by
> Also, since you are using the /etc/hosts file instead of the DNS system, the client (browser) also has those entries in its hosts file.  And, as Konstantin pointed out, you don't put the port number in the /etc/hosts file.
> If you are using DNS for the clients, make sure that it has entries for both hosts, pointing to the same IP address.

I'm not shure if I understand the meaning of DNS in this case
correctly. Do you mean a DNS on my local machine or do you mean the
DNS on a remote machine? I've got a pure domain hoster and I set an A
record entry such that the domain is forwarded to my server / ip
address 88.84.140.85. Both domains are actually pointing to this ip
address since both are hosted by the same domain hoster. I do not
explicitly use DNS on my local machine, at least I did not configure
it.

And how can the client (browser) have entries in a host file?


The current status is that when calling www.my1rstdomain.com:8080
points to the webapp installed for www.my2nddomain.com:8080.


2012/11/27 Jeffrey Janner <Je...@polydyne.com>:
>> -----Original Message-----
>> From: Paul van Hoven [mailto:paul.van.hoven@googlemail.com]
>> Sent: Tuesday, November 27, 2012 2:13 PM
>> To: Tomcat Users List
>> Subject: Re: Tomcat with multiple domains
>>
>> Thanks for the answer. I followed the tutorial you propose (
>> http://wiki.apache.org/tomcat/TomcatDevelopmentVirtualHosts ). But it
>> is still not working. Here is my new configuration
>>
>>
>> server.xml
>> <Host name="2nddomain.com"
>> appBase="/opt/apache-tomcat-7.0.32/2nddomain.com" unpackWARs="true"
>> autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
>>               <Alias>2nddomain.com</Alias>
>>               <Alias>www.2nddomain.com</Alias>
>>       </Host>
>>
>> The directory
>> /opt/apache-tomcat-7.0.32/2nddomain.com
>> contains a ROOT.war file.
>>
>> I edited the /etc/hosts file and added the following entries:
>> 88.84.140.88  www.2nddomain.com:8080
>> 88.84.140.88  www.1rstdomain.com:8080
>>
>> Then I restarted the system and the tomcat server. Entering
>> www.2nddomain.com:8080 sends me to 1rstdomain.com. I noticed that the
>> file  "/opt/apache-tomcat-7.0.32/2nddomain.com/ROOT.war" remains
>> untouched by tomcat, at least nothing is extracted from the war file.
>>
>> So what else am I missing here?
>
> Make sure that the new <Host></Host> definition is nested inside the <Engine></Engine> tags.
> You also do not need the first <Alias> line.  The name= parameter takes care of that mapping for you.
> In general, the nesting works this way:
> <Server ... >
>   <Service ... >
>     <Connector ... />
>     <Connector ... />
>     <Engine ... >
>       <Host name="host1.com" ... >
>         <Alias>www.host1.com</Alias>
>       </Host>
>       <Host name="www.host2.com" ... >
>         <Alias>host2.com</Alias>
>       </Host>
>       <Host name="www.myhost.com" ... />
>     </Engine>
>   </Service>
> </Server>
>
> There are a myriad other tag sets that could be included in there and it's very important that they be nested properly to work properly.
>
> Also, since you are using the /etc/hosts file instead of the DNS system, the client (browser) also has those entries in its hosts file.  And, as Konstantin pointed out, you don't put the port number in the /etc/hosts file.
> If you are using DNS for the clients, make sure that it has entries for both hosts, pointing to the same IP address.
>
>
> ---------------------------------------------------------------------
> 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: Tomcat with multiple domains

Posted by Jeffrey Janner <Je...@PolyDyne.com>.
> -----Original Message-----
> From: Paul van Hoven [mailto:paul.van.hoven@googlemail.com]
> Sent: Tuesday, November 27, 2012 2:13 PM
> To: Tomcat Users List
> Subject: Re: Tomcat with multiple domains
> 
> Thanks for the answer. I followed the tutorial you propose (
> http://wiki.apache.org/tomcat/TomcatDevelopmentVirtualHosts ). But it
> is still not working. Here is my new configuration
> 
> 
> server.xml
> <Host name="2nddomain.com"
> appBase="/opt/apache-tomcat-7.0.32/2nddomain.com" unpackWARs="true"
> autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
> 		<Alias>2nddomain.com</Alias>
> 		<Alias>www.2nddomain.com</Alias>
> 	</Host>
> 
> The directory
> /opt/apache-tomcat-7.0.32/2nddomain.com
> contains a ROOT.war file.
> 
> I edited the /etc/hosts file and added the following entries:
> 88.84.140.88	www.2nddomain.com:8080
> 88.84.140.88	www.1rstdomain.com:8080
> 
> Then I restarted the system and the tomcat server. Entering
> www.2nddomain.com:8080 sends me to 1rstdomain.com. I noticed that the
> file  "/opt/apache-tomcat-7.0.32/2nddomain.com/ROOT.war" remains
> untouched by tomcat, at least nothing is extracted from the war file.
> 
> So what else am I missing here?

Make sure that the new <Host></Host> definition is nested inside the <Engine></Engine> tags.
You also do not need the first <Alias> line.  The name= parameter takes care of that mapping for you.
In general, the nesting works this way:
<Server ... >
  <Service ... >
    <Connector ... />
    <Connector ... />
    <Engine ... >
      <Host name="host1.com" ... >
        <Alias>www.host1.com</Alias>
      </Host>
      <Host name="www.host2.com" ... >
        <Alias>host2.com</Alias>
      </Host>
      <Host name="www.myhost.com" ... />
    </Engine>
  </Service>
</Server>

There are a myriad other tag sets that could be included in there and it's very important that they be nested properly to work properly.

Also, since you are using the /etc/hosts file instead of the DNS system, the client (browser) also has those entries in its hosts file.  And, as Konstantin pointed out, you don't put the port number in the /etc/hosts file.
If you are using DNS for the clients, make sure that it has entries for both hosts, pointing to the same IP address.  


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


Re: Tomcat with multiple domains

Posted by Paul van Hoven <pa...@googlemail.com>.
Thanks for the answer. I followed the tutorial you propose (
http://wiki.apache.org/tomcat/TomcatDevelopmentVirtualHosts ). But it
is still not working. Here is my new configuration


server.xml
<Host name="2nddomain.com"
appBase="/opt/apache-tomcat-7.0.32/2nddomain.com" unpackWARs="true"
autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
		<Alias>2nddomain.com</Alias>
		<Alias>www.2nddomain.com</Alias>
	</Host>

The directory
/opt/apache-tomcat-7.0.32/2nddomain.com
contains a ROOT.war file.

I edited the /etc/hosts file and added the following entries:
88.84.140.88	www.2nddomain.com:8080
88.84.140.88	www.1rstdomain.com:8080

Then I restarted the system and the tomcat server. Entering
www.2nddomain.com:8080 sends me to 1rstdomain.com. I noticed that the
file  "/opt/apache-tomcat-7.0.32/2nddomain.com/ROOT.war" remains
untouched by tomcat, at least nothing is extracted from the war file.

So what else am I missing here?

2012/11/22 Caldarale, Charles R <Ch...@unisys.com>:
>> From: Paul van Hoven [mailto:paul.van.hoven@googlemail.com]
>> Subject: Tomcat with multiple domains
>
>> I found the following tutorial (very old) on the web:
>> http://onjava.com/pub/a/onjava/2006/08/30/publishing-multiple-sites-using-single-tomcat.html
>
> Probably best to completely ignore anything that old.
>
>> I payed attention to the offical Tomcat documentation in regard of this:
>> http://tomcat.apache.org/tomcat-7.0-doc/virtual-hosting-howto.html
>
> That's good to look at, as is this:
> http://wiki.apache.org/tomcat/HowTo#How_do_I_set_up_Tomcat_virtual_hosts_in_a_development_environment.3F
>
> The steps apply to production as well as development.
>
>> In my $CATALINA_HOME (which is /opt/apache-tomcat-7.0.32) I created
>> the folder "my2ndDomain"
>
> This is only speculation (too lazy to look at the code right now), but domain names are defined to be case-insensitive, and typically presented only in lower case.  What happens if you change my2ndDomain to my2nddomain everywhere?
>
>> <Context path="my2ndDomain" debug="0" reloadable="false"/>
>
> The above is really, really bad.  You shouldn't be putting <Context> elements in server.xml, and besides, the contents of that one are gibberish.  What did you expect to achieve with it?
>
>  - 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: Tomcat with multiple domains

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Paul van Hoven [mailto:paul.van.hoven@googlemail.com] 
> Subject: Tomcat with multiple domains

> I found the following tutorial (very old) on the web:
> http://onjava.com/pub/a/onjava/2006/08/30/publishing-multiple-sites-using-single-tomcat.html

Probably best to completely ignore anything that old.

> I payed attention to the offical Tomcat documentation in regard of this:
> http://tomcat.apache.org/tomcat-7.0-doc/virtual-hosting-howto.html

That's good to look at, as is this:
http://wiki.apache.org/tomcat/HowTo#How_do_I_set_up_Tomcat_virtual_hosts_in_a_development_environment.3F

The steps apply to production as well as development.

> In my $CATALINA_HOME (which is /opt/apache-tomcat-7.0.32) I created
> the folder "my2ndDomain"

This is only speculation (too lazy to look at the code right now), but domain names are defined to be case-insensitive, and typically presented only in lower case.  What happens if you change my2ndDomain to my2nddomain everywhere?

> <Context path="my2ndDomain" debug="0" reloadable="false"/>

The above is really, really bad.  You shouldn't be putting <Context> elements in server.xml, and besides, the contents of that one are gibberish.  What did you expect to achieve with it?  

 - 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