Vincent Veyron wrote:
Le lundi 28 novembre 2011 à 20:37 +0100, André Warnier a écrit :
That way, the policy holder can type
'http://extranet.insurance_company.com/clients/login' and have access to
the data, transparently hitting my server at as-pro.biz.
Not really. I think you need to read up more on how VirtualHosts work.


I certainly have a lot more to learn on that side, but do you care to
expand on what is wrong? it works as expected on my side, and my client
tested it. See : http://extranet.france-prevoyance.fr/clients/login
and :
http://as-pro.biz/clients/login

It works, but it is your choice of language for the explanation which triggered 
my comment.

Summary (and with a few shortcuts):
1) the user enters a URL in the browser, like :
http://extranet.france-prevoyance.fr/xyz
2) the browser makes a DNS lookup, getting the IP address for "extranet.france-prevoyance.fr". Suppose that it gets 193.251.178.45. 3) the browser connects via TCP to IP 193.251.178.45:80, and sends a HTTP request to it, which looks like :
GET /xyz HTTP/1.1
Host: extranet.france-prevoyance.fr
.. other headers and body if any

4) the server gets this request on the connection.
5) the server reads the Host: header, and tries to match that hostname to one of its VirtualHost configurations, by matching either ServerName or ServerAlias. 6) If it finds a match, the server configures itself using that VirtualHost configuration, and processes the request. (The matching name becomes the $r->hostname). If it does not find a match, the server adopts the configuration of the default VirtualHost (in Apache, that's the first configured VirtualHost), and serves the request using that configuration. 7) then the server, using this particular configuration, looks for what "/xyz" may be, so that it can serve it.
And at the next request, it does this all over again.

So, it is not that the client "transparently hits" your server "at as-pro.biz".
The client hits an IP address (the one given by the DNS), and sends an additional information which is the name of the (virtual) server that it really wants. And the server is not really "the as-pro.biz server". It is the httpd server at the IP address 193.251.178.45, and it "adapts its personality" at each request, to match the "Host:" header.

I know that it sounds like nitpicking for a question of vocabulary.
But I've found that really understanding the logical steps above helps a lot, in writing HTTP applications, in configuring Apache properly, and in diagnosing problems when they occur.

For example, with $r->server->server_hostname, you would probably always get the name which is in the "ServerName" directive of the configuration of that VirtualHost (*). But with $r->hostname, you will get the name which is really used in this client request (which may be the ServerName or an alias from ServerAlias).

(*) I must say that I haven't tried it, but I suspect that is what happens.


Reply via email to