tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier>
Subject Re: IP-based virtual hosting with Tomcat(6)
Date Wed, 29 Jul 2009 23:29:54 GMT wrote:
> All the vHosts are to be situated on the same server.
> The server may be addressed using any loopback address
> or any non-loopback addressed configured on the NICs of the
> server.
> Hence I have the mapping
> -> vhost1
> -> vhost 2
> Let's say that a request arrives at address (configured
> as an external address of this server).
> Which vHost would serve this request?


As per the subject and the previous couple of posts, you were talking 
about Connectors configured to answer IP addresses.
If there is no Connector configured for listening on IP address X, and a 
request arrives to the host for IP address X, Tomcat just won't pick it 
up and the connection request will be refused.
So the question about a "default host" in that case is kind of moot, I 
think.  Which was the reason for my cheeky note.

In addition :
 > The server may be addressed using any loopback address
only if the request originates from the same host.  Otherwise, it would 
never get there, since the loopback addresses, by definition, are not 
routable and not usable outside the host itself.
(You can never "ping" a host, from outside of that host, on any of its 
loopback addresses).

Maybe there is a slight misunderstanding here of how these things work.
What may be confusing is that one talks about "name-based virtual hosts" 
and "IP-based virtual hosts", as if they were just two variations of the 
same thing.  They are not, and the mechanism for each is very different.

A <Connector> has an IP address and a port, but no name.
A <Host> has a name, but no IP address.

A HTTP request is /always/ preceded by a TCP connection to an IP 
If nothing is "listening" to that IP address:port, the connection is 
refused, and the request is never made.

But let's suppose that a <Connector> is configured to accept connections 
on that IP address:port, and thus the connection is established.
That is step 1.

Step 2:
Once the connection is made (to Tomcat, through one Connector), then 
(and only then) the client /can/ send a request over this connection, 
This request, as a minimum (in HTTP 1.1), would have 2 lines like :
GET /something HTTP/1.1
Host: (name, or IP address but considered as a string/name)

That "Host:" header is then what the webserver would use, to scan 
through its defined "name-based virtual hosts" (<Host> tags in Tomcat), 
to find the appropriate one to answer this request.
This would normally be the Host whose "name" attribute matches the 
content of the HTTP request's Host: header.
If the webserver does not find such a matching Hist, it will usually 
default to the first-defined Host associated to that Connector, as the 
default host.
(At least Apache httpd and Tomcat do it this way).

But all this pre-supposes that the TCP connection was made first, which 
will not happen if there is not a Connector which explicitly "listens" 
on the IP address:port with which the client tries to make the connection.
Which was the reason for my "None" answer above.

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

View raw message