Why does typing an IP address instead of the corresponding domain name not show the website? [closed]

> host example.com
example.com has address 93.184.216.34
example.com has IPv6 address 2606:2800:220:1:248:1893:25c8:1946

I type 93.184.216.34 instead of http://example.com in Chrome. It doesn't load the website. Why?


Solution 1:

Because the proper HTTP Host header is often required to actually get the intended site.

It's very common to host multiple web sites on the same IP address and distinguish between them based on the HTTP Host header specified by the client (as well as the TLS SNI value nowadays in the case of HTTPS).

That is, when you entered http://example.com into your browser the Host header was example.com, but that is not the case when you entered 93.184.216.34. You reach the same web server in both cases, but you receive different responses (in this particular case 200 vs. 404).

Solution 2:

Because usually web servers use "virtual server" technology and are able to answer on your HTTP request within exactly the domain name you request, but not the IP address of the web servers. Thanks to hiding more than one domain name on one IP address.

For example, the Apache web server is able to respond to your HTTP request with an IP address using the section:

<VirtualHost *:80>
ServerName Default
...
</VirtualHost>

or if No VirtualHost used in configuration at all.

The VirtualHost feature in Apache was introduced in 1996.