can't access website by ip but I can access by fully qualified domain

11,140

Solution 1

There are a variety of reasons this might be the case. Here are just a couple:

  • host headers - In short, the webserver might host multiple websites on a single IP address. Without the domain name, it cannot display the proper website.

  • load balancing or similar device - the IP address might not be for a website, but to a load balancer, which distributes network load to other devices.

  • name resolution - the name resolution to IP had been changed. For example, let's say the website's address has changed and you manually entered it into your HOSTS file to go to the proper IP.

Solution 2

Apache and nginx both (not sure about others....) can serve multiple sites from the same IP based on the host name that is used to connect and request the file(s).

But when you access the server via the IP address, there must be a virtual host defined to service the name used (the IP). The fact that the server is generating an error indicates that there is something "wrong" on the server's config - either it isn't set up to respond to the IP at all, or if it is responding and serving up a PHP or other script that script has issues of some type.

Share:
11,140

Related videos on Youtube

catalin
Author by

catalin

Updated on September 18, 2022

Comments

  • catalin
    catalin over 1 year

    So it seems I can't browse a website by IP, but I can browse using it's hostname.

    C:\Users\c>nslookup www.example.com
    Non-authoritative answer:
    Name:    cx-cdn-bre.gss.consultix.net
    Addresses:  62.168.203.241
              62.168.202.241
    

    Trying to access 62.168.203.241 is displaying an "nginx Internal Server Error" But if I access www.example.com, the page loads. How is this possible?

    • Worthwelle
      Worthwelle over 5 years
      It is likely that multiple domains are served from the same server. In this case, the server relies on the headers of the request to specify what website to serve. If there is no default configured, then it will return a server error.
    • S.Leon
      S.Leon over 5 years
      Apache, Nginx and IIS prohibit direct access to websites through IP addresses to prevent malicious resolution. In general, websites are not allowed to access directly through IP addresses. Some websites do not restrict access by IP addresses, but when using IP addresses to access websites, they redirect IP addresses to the corresponding domain names. Of course, you can make adjustments to Apache, Nginx, and IIS to allow certain websites to access directly through IP addresses.
  • Ramhound
    Ramhound over 5 years
    @FollowerOfLelouch - You should edit your answer, and improve it, instead of submitting comments.
  • user1686
    user1686 over 5 years
    Isn't the load-balancer case still just the same "Host headers" problem?
  • Keltari
    Keltari over 5 years
    @grawity Im just listing various reasons why.
  • user1686
    user1686 over 5 years
    @FollowerOfLelouch: The thing is, your "explanations" only keep repeating the same thing from OP's question. Why does Fastly say 'unknown domain'? That's not an explanation; that's what the OP was asking already.
  • catalin
    catalin over 5 years
    You're right. It's the virtual host config. Basically, when I was requesting the GET method, host header was sending the IP, and the server was expecting the hostname. Hence the server's virtual host config refused my request and threw me "internal server error". I was able to test it using BurpSuite. I've requested the IP and passed the hostname in the host header, and the page loaded successfully. I've tested the vice-versa also, requested the FQDN and modifed the host header with the IP, and I got the same "internal server error".
  • catalin
    catalin over 5 years
    You're right. It's because of the headers and virtual host config. Basically, when I was requesting the GET method, host header was sending the IP, and the server was expecting the hostname. Hence the server's virtual host config refused my request and threw me "internal server error". I was able to test it using BurpSuite. I've requested the IP and passed the hostname in the host header, and the page loaded successfully. I've tested the vice-versa also, requested the FQDN and modifed the host header with the IP, and I got the same "internal server error".