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

Prevent apache from using machine host name

· 52CE 我爱测

In our office, we have a public facing server whose machine hostname is server16 . We want Apache to only respond to requests on server.example.com . We have a VirtualHost entry with ServerName server.example.com . The problem is…

问题原文

原帖链接 · dallpickle343 · CC BY-SA 4.0

In our office, we have a public facing server whose machine hostname is server16. We want Apache to only respond to requests on server.example.com. We have a VirtualHost entry with ServerName server.example.com. The problem is, if we include a VirtualHost entry for server16.example.com, then apache responds to it, so we have it respond with 403: Forbidden, but we would like it to not accept a request to server16.example.com at all.

We have talked with our system admins, and for certain reasons, we can't change the hostname of the server. Is there anyway within Apache to do what we need?

已采纳解答

原帖链接 · Stephen Ostermiller · CC BY-SA 4.0

What you are asking is not possible at the web server level. The server does not know what host name is requested until after it has accepted the connection. Here is what happens when you request a URL such as server.example.com or server16.example.com:

  1. The client looks up the IP address for the host name. In either case, it will get the same IP address.
  2. The client opens a connection to that IP address on port 80.
  3. The client sends the request which includes the document path and the host name. In its simplest for it looks like:

    GET / HTTP/1.1
    Host: domain.example.com
    
  4. The server decides what HTTP response to send based on its configuration.

Configuring the server to respond with "403 Forbidden" is perfectly acceptable. I would say that a "404 Not Found" would be more appropriate because the server doesn't have any documents for that domain.

The only way to prevent the connection altogether would be for server16.example.com to be removed from DNS. If that DNS were removed, then a connection for that domain name would not be able to be established.

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

资料来源与适用范围

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

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

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