Cannot access the GitHub Pages website by IP Address

domain-name-systemgithubhttpload balancing

My custom domain works with GitHub Pages but I would like to understand how it actually works.

For this example I am not using my custom domain at all. My GitHub Pages repository does not contain a CNAME file.


E.g. Given a GitHub Pages repository without a CNAME file: example.github.io

DNS request for example.github.io resolves to 185.31.16.133

running the ping command for example.github.io also returns the same IP address: 185.31.16.133

When I open the website http://example.github.io in the browser, the browser show the contents of the actual website.

When I type an IP address 185.31.16.133 instead or make an HTTP GET request with a tool like Postman, all I see is a GitHub Pages 404 error.

Why can't I access my GitHub User page by an IP address directly? I thought that browsers replace hostname part of the URL with the IP address response of a DNS lookup, prior to making an HTTP request.

Best Answer

Yes, web browsers does a DNS lookup and uses that ip address for the connection. They also take the original host name and send it as part of the Host http header. This allows a web server to serve multiple web sites from the same ip address.

curl http://185.31.16.133/

vs.

curl --header "Host: jzelenkov.github.io" http://185.31.16.133/
Related Topic