-2

Are the following two independent of each other:

  • the hostname resolved by DNS and

  • the hostname resolved by web server for virtual hosting ?

Thanks.

Tim
  • 1,467
  • 3
  • 25
  • 38
  • 2
    The webserver doesn't resolve hostnames. Have a look at https://serverfault.com/a/520201/120438 for a full explanation of what happens on the web server side. – Jenny D Feb 13 '19 at 15:27

1 Answers1

4

I think I know what you're asking here, and yes, it is.

  1. The DNS lookup to mywebsite.com is a function of your local machine. You type www.mywebsite.example, DNS resolves it to 192.0.2.4 and then:

  2. The browser makes a request to 192.0.2.4, and as part of that request it specifically asks for www.mywebsite.example. This is called the host header.

It's that host header which the web server uses to decide on which virtual host to display. Indeed, in the early days, it simply wasn't supported by all browsers and it has nothing to do with DNS.

Patrick Mevzek
  • 9,273
  • 7
  • 29
  • 42
Dan
  • 15,280
  • 1
  • 35
  • 67
  • 1
    "HTTP/0.9" did not have a `host` header (as it had no headers at all), but HTTP/1.0 did. Also for HTTPS, the webserver will base its choice also on the name included in the TLS SNI extension, as it may need to know the name in case of virtual hosting to send the correct X.509 certificate before even completing the TLS handshake and being able to read the `host` header. – Patrick Mevzek Feb 13 '19 at 15:15
  • Thanks. Does the client necessarily put the hostname that it uses for DNS resolving in the Host header of its request? (I guess no, if I understand your reply correctly. ) – Tim Feb 13 '19 at 22:38
  • @Tim Normal browsers use the same hostname in the Host header. It's quite possible to write a client that doesn't; in fact, there are some where you can specify another hostname. Those are mostly used for testing purposes though. – Jenny D Feb 14 '19 at 09:09