【问题标题】:DNS record for help.example.com returns 404help.example.com 的 DNS 记录返回 404
【发布时间】:2019-12-05 17:10:10
【问题描述】:

我有一个域example.com。我想将help.example.com 映射到example.com。 DNS 记录是:

Hostname           Type     Value
example.com        A        93.184.216.34
help.example.com   A        93.184.216.34
www.example.com    CNAME    example.com

我可以使用example.comwww.example.com 访问该网站,但是当我尝试使用help.example.com 时,我得到404 Not Found。:

未找到
在此服务器上找不到请求的 URL /。
此外,在尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误。

所以我想知道为什么help.example.comA 记录没有重定向到example.com


额外信息:

  • 我的 .htaccess 由单行组成:

    ErrorDocument 404 "Cannot find that URL"
    

    如果我尝试访问example.com/some_random_string,我会(如预期)得到Cannot find that URL。但是,如果我尝试访问help.example.com/some_random_string,我会收到上述Not Found 消息。所以似乎 .htaccess 被help.example.com忽略了

  • ping example.comwww.example.comhelp.example.com 返回相同的 IP 地址。

  • 我还尝试将A 记录替换为:

    help.example.com   CNAME     example.com
    

    但这会返回相同的Not Found 消息。

【问题讨论】:

    标签: apache web dns cname a-records


    【解决方案1】:

    您的问题出在网络服务器配置中。根本不在 DNS 中。
    我假设您使用 Apache,所以您需要告诉 Apache example.com www.example.com help.example.com 具有相同的根目录。
    例如,如果您使用 VirualHost 配置和 Ubuntu,请查看 /etc/apache2/sites-enabled/example.com.conf
    应该有

    <VirtualHost *:80>
        ServerAdmin admin@example.com
        ServerName example.com
        ServerAlias www.example.com help.example.com
        ...
    </VirtualHost>
    

    如果您使用其他操作系统/配置/WebServer,您可以谷歌/查看您的配置如何工作以及在哪里添加您的域名。不在 DNS 中。

    【讨论】:

    • 实际上,当我想到它时,您可能没有设置您的服务器。您可能使用了一些网络托管服务。然后您需要登录到您的控制面板并在那里添加domainalias。但房东可能会为此要求额外付款。无论如何,您的 DNS 工作正常,网络服务器收到您的请求,他只是不知道 help.example.com 在磁盘上的位置。
    • 太棒了,我将 ServerAlias 命令包含在我的 example.com.conf 文件中并解决了问题。
    【解决方案2】:

    CNAME 记录中缺少点。应该是

    help.example.com.   CNAME     example.com.
    

    CNAME 记录中应使用所谓的 FQDN(Fully Qualified Domain Name)。 没有点名称服务器会将值 $origin 变量附加到末尾。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-05
      • 2011-07-02
      • 2010-11-26
      • 1970-01-01
      • 2016-01-14
      • 1970-01-01
      • 2019-11-27
      • 2021-07-23
      相关资源
      最近更新 更多