tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier>
Subject Re: Tomcat with multiple domains
Date Thu, 29 Nov 2012 12:33:15 GMT

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 ""

2) the browser parses this URL in :
protocol : http
hostname :
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

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 '' 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 
'' 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

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

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://", and you say that the webapp which answers is started in the 
Host with hostname "".
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:
For additional commands, e-mail:

View raw message