I have website http://waycoolblog.com, but I cannot access it through its ip address

Why is this happening?

My main question is whether this is a common thing. In my app I am trying to the resolve the sitename myself and trying to connect with the ip-address instead of sitename.

I want to make sure this that works properly.

migrated from stackoverflow.com Jun 8 '10 at 23:10

This question came from our site for professional and enthusiast programmers.

  • 3
    It will work fine, but you will have to send the header Hostname: waycoolblog.com as part of your HTTP request. – psmears Jun 8 '10 at 12:21
  • @Martin - oops, you're right of course! Thanks for pointing that out! – psmears Jun 8 '10 at 13:07

Not knowing the server on which you are running, but in IIS, there is the host-header mapping function.

This allows multiple websites to run from the same IP address, but requires that the domain name of the web site is supplied as the "Host" http request header. The server queries this header and serves the content from the appropriate site.

Any request coming in via the IP address will not have "waycoolblog.com" as the host header. If your server is hosting more than one web site, chances are that yours is not the 'default', so the server won't serve your site.

  • Based on the default site for the IP and a reverse DNS lookup, it looks like the server is used for shared hosting. This behaviour is normal for cheap hosting. – Quentin Jun 8 '10 at 12:20

Maybe the server your site is on is using hostname-based VirtualHosting?


Hostname-based virtual hosting is extremely common. Without it, the shortage of IP addresses would be much more serious. How it works? The HTTP/1.1 client passes a Host header as part of its request that says which host was of interest (waycoolblog.com in your case) and the HTTP server works out which set of content to serve up based off that. That enables the same IP address to serve many different hostnames' content, keeping hosting much cheaper. It's also a feature of every production-grade standard web server software system. Apache does it, as does IIS and every other one I know about that isn't a research toy.

The fix for you is to pass the Host header correctly in the client code that is making the connection. Then everything should Just WorkTM.

  • Is there any other case which i need to handle when i try to access the website using the ip-address? Does that work always when that host header is passed in the request? – railscoder Jun 8 '10 at 13:08
  • @railscoder: It depends on your client library, really. As long as the Host header is set, you'll be fine, but that's usually done by the client library for you based off the URL you passed in for it to fetch (because that's the Right Thing). IIRC, things can be more complex with HTTPS-based fetches, but I don't know the exact nuances there. – Donal Fellows Jun 8 '10 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.