> 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?
> 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?
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).
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.
In Apache, you can host many websites using just one single IP address. This is called virtual hosting. It's how subdomains can be created, even standalone domains. This is done by setting up an Apache configuration file containing VirtualHost directives for each domain/subdomain.
An example HTTP server that has two virtual hosts, example1.com and example2.com can look like this (IP address definition):
<VirtualHost 93.184.216.34:80>
ServerName example1.com
ServerAlias www.example1.com
DocumentRoot /var/www/example1.com
</VirtualHost>
<VirtualHost 93.184.216.34:80>
ServerName example2.com
ServerAlias www.example2.com
DocumentRoot /var/www/example2.com
</VirtualHost>
It can also look like this (name-based definition):
<VirtualHost *:80>
ServerName example1.com
ServerAlias www.example1.com
DocumentRoot /var/www/example1.com
</VirtualHost>
<VirtualHost *:80>
ServerName example2.com
ServerAlias www.example2.com
DocumentRoot /var/www/example2.com
</VirtualHost>
In both cases, two virtual host records are created internally in memory and used by Apache to compare against when a URI request arrives.
When a user types in the IP address via a user agent, the first virtual host listed in the configuration file is used as the primary domain (i.e. in this case example1.com).
When a user types in a domain name, the request is sent to a public Internet DNS network (ICANN) which provides the IP address associated with it. You registered both via an ICANN registrar (like GoDaddy). You must have both of these correct and give some time before propagation takes hold to all DNS servers on the ICANN network. These days it can take up to 24 hours.
When the request is routed to your Apache HTTP server, the IP address and domain name are matched against the list of internal VirtualHost records. When one is found, the document root is used to form the full filesystem path to the object resource to return back to the user agent. If not, a HTTP 404 is sent along with any error document associated with it.
I like to use the "house" terminology.
You can quite easily send a letter to a house without a name on it and it'll arrive at the house.
If you put the person's name on it then you're sending to the intended recipient.
The destination is the same but how it is handled when it reaches the house is different.
When you specify the site, i.e. www.example.com then the server knows how to handle the request and which host it is intended for and which site to serve back.
The key term to search for is "name based virtual hosting".
People want to allocate multiple hostnames to the same web server and serve different content for each hostname. This is known as virtual hosting (not to be confused with the more recent concept of virtual machines).
Initially virtual hosting was done by allocating multiple IP addresses to the server, the sever could then send different content based on the IP address used, but this was seen as wasteful.
Therefore the "host" header was introduced, initially as an extension but then later made a mandatory part of the http 1.1 specification in 1997. This header specifies the hostname the client asked for. The server can then serve up different content based on the value of the header.
To keep costs down for web servers, a lot of web servers host multiple websites. They do this by using virtual hosts, or Vhosts, in apache2/nginx/etc. So if you go directly to the website's IP Address, you will most likely get an "Apache is working" screen, or possibly even get redirected to the web server's main website.
A Vhost looks at the incoming website address and compares it to the ServerName or ServerAlias names in the enabled Vhosts files. If one of them matches, that specific website is loaded.
Unless the website has a massive load (high numbers of unique visitors/page views) or drives high load applications (think youtube.com, facebook, etc.) it is probably more cost effective to operate on a shared server. It would be a waste of money to get yourself a dedicated server (starting at $60/mo) just to run a Wordpress blog website. You're better off getting a shared platform on a server with probably 200+ websites on one server. Costs will be more in the area of $5/mo.
Another reason for doing this is the lack of IP addresses. There simply isn't enough IPv4 addresses remaining. It is only through the use of NAT for home/business networks and the use of Vhosts that we have any remaining at all. Even when IPv6 becomes main stream, servers will probably stick to Vhosts (server costs).
A dedicated IP address is expensive, while creating a new website on a server is basically free.
What happens is that the hosting company rents a single IP address that points to a physical server, then hosts thousands of websites on that IP address using the "virtual host" feature
Think like a P.O. Box, if you just write down the post office address but without the box number, the mail won't be delivered.
There's a lot of answers here with technical detail, but I think the simplest high-level explanation is that even if a web server is properly listening for http traffic on it's IP address, the server must usually also be configured to answer for a particular domain name, and that name must be in the request sent by the client (i.e the web browser)
I say "usually" because it's almost always done this way, but there are in fact methods where you can setup the http server to answer if only the IP address is used.
We need to understand the differences between Virtual IPs and Dedicated IPs.
If a website has a dedicated (not shared) IP, then (for example) http://123.456.789.012 will bring up the website.
Try this, which is the Dedicated IP address of a site that I own, www.negativeiongenerators.com: http://75.126.128.174 But as others have said, it's usually not a good idea.