tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier ...@ice-sa.com>
Subject Re: tomcat virtual host
Date Thu, 20 Nov 2008 21:44:34 GMT
Caldarale, Charles R wrote:
>> From: mtail@free.fr [mailto:mtail@free.fr]
>> Subject: Re: tomcat virtual host
>>
>> status, or does something else happen?  Is the DNS name
>> "mysvn" defined on the machine your browser is running on?
>>
>> Internet Explorer could not display this web  page
>> i test this in local machine, so i do not use a DNS.
> 

mtail,

The gurus here are flying high, and a bit intimidating sometimes.
So allow me to try, since for once I can maybe be useful here.

It is not enough to define a virtual host in Tomcat.  Your browser must 
also know "where" that virtual host is (on which machine). Even if this 
all happens on one single machine, the browser does not know who "mysvn" 
is, unless you give him a way to find out.
So let's start at the beginning.

1) When you type in your browser a URL like
http://mysvn:8080/something.html
the first thing the browser has to do, is to find an IP address that 
corresponds to the hostname "mysvn".
That is because, on the Internet, machines find one another via IP 
addresses (like 123.23.34.102), and not by names (like "mysvn"). Names 
are only something for humans, easier to remember than numbers.

2) There are 2 places where the browser can find a translation of a host 
name into a host IP address, and it will try them in this order :

(a) : in the local "hosts" file.
Under Windows, it is usually c:/windows/system32/drivers/etc/hosts
and under Unix, it is usually /etc/hosts

(b) : using the DNS system.
That means, the browser knows the IP address of a "DNS server", which is 
another computer which has access to a long list of translations between 
host "names" and host "IP addresses", and it will ask that server.

So, the browser will first try (a).  If the browser is looking for the 
IP address of "mysvn", and if there is a line in (a) like
1.2.3.4 mysvn
then the browser is happy : it now knows that the server IP address of 
"mysvn" is 1.2.3.4, and it can stop looking.

If the browser does not find a translation in (a), then it will ask (b) 
(the DNS system) for a translation.

If the DNS system also does not know, then it will send back "I don't 
know", and your browser will say "Cannot display that page", because it 
cannot even find the IP address of the server to which it should be talking.

3) When the browser has obtained a translation for "mysvn" into an IP 
address, then (and only then) it can go one step further :

It can now compose a HTTP request and send it to that IP address 
1.2.3.4.  This HTTP request will look like this :
GET /something.html HTTP/1.1
The browser will also add a second line to that request, like
Host: mysvn


4)
If all the above happened correctly, then the Tomcat listening at the IP 
address 1.2.3.4 will receive the request from the browser.

It is very important that you understand this :
Tomcat only receives the request if the browser has sent it to the 
correct IP address of the host where the Tomcat server runs.  That is 
true even if this all happens on one single machine.
If your browser could not get an IP address for "mysvn", or if it got 
the wrong one, then Tomcat never even sees the request.

5) But let's suppose that everything above went fine, and that Tomcat 
receives the request.
Tomcat now looks at the second line of the request, the one that says :
Host: mysvn

That is when the Tomcat virtual hosts come into play (but not before).

Tomcat will now look if it has a Host named "mysvn".
If it has one, it will use that Host configuration to answer the request.
(If Tomcat has no such Host, then it will use its "default host" to 
answer the request anyway.)

6) Now there can still be an error :

If the browser asked for the page "/something.html", and Tomcat does not 
find that page in the document area of that virtual Host, then Tomcat 
will return an error "not found" to the browser, and the browser will 
also say "Cannot display that page".
But the point is, this is another kind of error, and it happens later.

Your problem is probably due to the first reason : your browser cannot 
even find an IP address for the server "mysvn".
It cannot find it, because it looks first in your local hosts file, and 
there is no line there with "mysvn".  Then it asks the DNS system, and 
the DNS system also does not know the IP address of "mysvn".

On the other hand, when your browser tries to find the address of 
"localhost", then it *does* find it in the local hosts file, and that is 
why your URL
http://localhost:8080
works fine.

-- note --

The IP address 127.0.0.1 is special : it always means "this machine".
So if you do "ping 127.0.0.1" on any computer, that computer will always 
ping itself.
Or if you ask your browser
http://127.0.0.1
the browser will try to contact a HTTP server on this same machine.

Similarly, on almost every computer, there is a line in the local hosts 
file, like this :
127.0.0.1 localhost

That means that whenever a program on this machine is trying to get the 
address of the host "localhost", it will always find the response 
"127.0.0.1" (because it first looks in the hosts file).
That's why, if you enter "ping localhost", you will see the same as if 
you enter "ping 127.0.0.1".
It is also why, if you enter in your browser
http://localhost:8080
the browser will try to contact the HTTP server on this same machine 
(because "localhost" is first translated to "127.0.0.1", and that IP 
address always means "this machine").

-- End of note --


To summarise :

If you want your browser to find the correct (local) Tomcat virtual 
hosts "localhost" and "mysvn", and you want Tomcat to answer with the 
correct virtual host, and all of this happens on the same machine, then 
you have to do 2 things :

A) you have to make sure that in your local hosts file, there are these 
2 lines :
127.0.0.1 localhost
127.0.0.1 mysvn

That is because you want your browser to send the HTTP request to the 
local machine (127.0.0.1) in both cases :
- when you use the URL : http://localhost:8080
- and when you use the URL : http://mysvn:8080

B) you have to configure 2 virtual hosts in Tomcat :
one <Host> for "localhost"
and one <Host> for "mysvn"

Both A and B are necessary.
You have done B, but you probably did not think of A.









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


Mime
View raw message