-4

http://example.com has the IP address 93.184.216.34.

From what I've read about IP addreses and ports, this leads me to believe that appending the port 80 to the end of it (93.184.216.34:80) should also load the same page. However instead it gives me a 404 Not Found error.

Why can't I access http://example.com through its IP address?

James Donnelly
  • 103
  • 1
  • 7
  • 5
    Many times, more than one domain runs on the same IP. You will need to send a `host` header containing the domain you want to view. And then there's server configuration that might prevent you from viewing anything on IP at all. So don't believe everything you read ;-) – Oldskool Aug 20 '15 at 13:44
  • `Is there any way I can access http://example.com through its IP address and port combination?`. Why would you want/need to? – GregL Aug 20 '15 at 13:50
  • @GregL no reason. It's more of a hypothetical thing. I was under the impression that http://{ip-address}:80 would lead me to http://example.com, but from what Oldskool has said it seems this isn't the case! – James Donnelly Aug 20 '15 at 14:06
  • I've updated the question to remove some of the unnecessary bits. – James Donnelly Aug 20 '15 at 14:47
  • Ignoring the scenarios where this doesn't work (as already stated in the comments) and addressing only the scenario where this does work, it isn't necessary to explicitly type the port number (:80). A web browser attempts to connect to port 80 by default. – joeqwerty Aug 20 '15 at 15:22
  • I *strongly* recommend you to include more details in your question, as otherwise you're leaving us guessing and with guessing nobody can really help you. here are the answers for your questions: 1. you can! 2. yes, you need to configure your web server to serve your content from hostname _AND_ IP. – alexus Aug 20 '15 at 13:52
  • David and Jeff may have the same phone number, but getting David on the phone and getting Jeff on the phone still result in you talking to a different person. You connect to the same phone endpoint, but what happens after you connect is different. – David Schwartz Aug 20 '15 at 17:59

1 Answers1

7

The HTTP protocol allows the client application (usually a web browser) to create HTTP requests containing the name of the web site it wants to contact; this allows multiple web sites to coexist on the same IP address and port.

All web servers can be configured to serve different contents based on the name of the web site the client is asking for; also, they can have a default web site, which is used if the request doesn't explicitly specify any host name.

In your case, you are (your browser is) contacting the web server without specifying a host name, because you used the server IP address in the URL; it seems like the web server is not configured to handle this type of request, thus it returns an error.

Most web browsers automatically use whatever you specify in the URL as the host name to request (or nothing if you used an IP address); thus you can't control what request is actually being made. Some developer tools allow you to perform custom requests, or you can do them manually by connecting to TCP port 80 on the destination server (even using something as simple as telnet) and talking a bit of HTTP. For example, this (stripped down) request returns the correct page from the web site example.com:

GET / HTTP/1.1
Host: example.com

It basically means "give me the contents at the path / (the web site root) for the site called example.com".

Massimo
  • 70,200
  • 57
  • 200
  • 323