Why Direct IP Access Fails: The Hidden Role of the Host Header in HTTPS
Although you can obtain a website’s IP address, accessing it directly via HTTPS often fails because the HTTP request’s Host header differs, and servers use this header to verify the intended domain, leading to 403 errors unless the correct Host value is supplied.
When you visit a website, the client first resolves the domain name to an IP address and then sends HTTP requests to that IP.
If you already know the IP address, you might think you can skip DNS and request the site directly using the IP.
Using Baidu as an example, we ping the domain and obtain the IP
14.119.104.189. Accessing
https://14.119.104.189in a browser results in a refusal.
To understand why, we capture the traffic with Fiddler. Comparing a request to the domain and a request to the IP, we find that only two request‑header fields differ:
Hostand
Cookie.
The
Hostheader contains the domain name when accessing via the domain, but contains the IP address when accessing via the IP. The server uses this header to determine which virtual host should handle the request.
When we send a request to
https://14.119.104.189with Postman, the server returns a 403 error. After editing the
Hostheader to
www.baidu.comand sending the request again, the access succeeds.
Thus, the reason direct IP access fails is that the server distinguishes requests by the
Hostheader; an IP‑only request does not match any configured virtual host, leading to denial.
Note: Accessing the IP over HTTPS may also trigger a certificate warning because the SSL certificate is issued for the domain name, not the IP address.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.