大网数据广告活动
网站运营与故障问答

Why does typing in my site's IP address bring up a different site?

· 52CE 我爱测

I do not understand how domains are connected to IP addresses. I have a certain domain e.g. example.com. I run ping example.com and get its IP address from DNS query. When I type this IP in address line in browser, it brings me t…

问题原文

原帖链接 · user87035 · CC BY-SA 3.0

I do not understand how domains are connected to IP addresses. I have a certain domain e.g. example.com. I run ping example.com and get its IP address from DNS query.

When I type this IP in address line in browser, it brings me to another site. Please explain to me the reason that might happen.

已采纳解答

原帖链接 · xsrf · CC BY-SA 3.0

The HTTP protocol that is used to load websites by your browser supports a "Host" header which tells the server which hostname was typed into the url bar of the browser. This way, the same server (same IP) can handle different websites.

Imagine www1.example.com and www2.example.com both resolve to 127.0.0.42.

The Server on 127.0.0.42 on port 80 listens to HTTP requests. If you open http://www1.example.com in your browser, the browser connects to 127.0.0.42:80 and sends the Host: www1.example.com header along with the request. This way the server can serve the site for www1.example.com.

If you enter http://www2.example.com, your browser also connects to 127.0.0.42:80, but this time sets the Host: www2.example.com header, thus the sever knows that this time it has to serve the other page.

If you open http://127.0.0.42 in your browser, the server will get the Host: 127.0.0.42 header along with the request. This time the server may not know which site to serve, so it may present an error, or fall back to a default website. This is why you may see a different site if you browse to the IP instead of the hostname.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2018-03-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。