Why does an HTTP/1.1 request need a Host header?
One server IP can host many websites. The TCP connection only carries the IP address, so the Host header tells the server which site the browser wants, letting it choose the right content. HTTP/1.1 requires it.
Explain it simply
A single apartment building (one IP address) has many shops inside. The street address alone does not say which shop you want, so you also say the shop's name. The Host header is that shop name.
Example
GET /index.html HTTP/1.1
Host: shop.example.com# Same IP, two different sites, selected only by the Host header
curl -H "Host: shop.example.com" http://203.0.113.10/
curl -H "Host: blog.example.com" http://203.0.113.10/This is called name-based virtual hosting. It is why shared hosting can put thousands of sites on a few IPs, and why reverse proxies route by hostname.
For HTTPS the same problem happens earlier: the TLS handshake needs to choose a certificate before any HTTP request is sent. SNI solves that by sending the hostname in the ClientHello.
What to say in the interview
"Host selects the virtual host when many sites share one IP. HTTP/1.1 makes it mandatory. HTTP/2 carries the same information in the :authority pseudo-header, and TLS uses SNI for the same job."
Common mistakes
- Thinking DNS alone tells the server which site was requested. DNS only gives the IP.