加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

domain-name-system – DNS和子域的问题

发布时间:2020-12-14 23:05:47 所属栏目:资源 来源:网络整理
导读:我有一个在Ubuntu服务器上运行的Apache(14.04).我已经配置了DNS A记录和VH,以便拥有一个域和两个子域,如下所示: example.com subdomain1.example.com subdomain2.example.com 一切运行正常,但问题是当我尝试通过服务器ip访问我的网站时,浏览器显示subdomain
我有一个在Ubuntu服务器上运行的Apache(14.04).我已经配置了DNS A记录和VH,以便拥有一个域和两个子域,如下所示:
  • example.com
  • subdomain1.example.com
  • subdomain2.example.com

一切运行正常,但问题是当我尝试通过服务器ip访问我的网站时,浏览器显示subdomain1.example.com内容而不是example.com内容.如果我输入example.com,就不会发生这种情况,在这种情况下一切顺利,但我担心这可能会成为未来的问题,或者我做错了什么……

这是我的example.com和subdomain1.example.com的Apache VH配置(subdomain2与subdomain1完全相同):

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAdmin contact@example.com
    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost>

<VirtualHost *:80>
    ServerName subdomain1.example.com
    ServerAdmin contact@example.com
    DocumentRoot /var/www/subdomain1

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost>

希望我已经解释得很好……
谢谢!

解决方法

从 Apache docs起

When a request is received,the server first maps it to the best
matching based on the local IP address and port
combination only. Non-wildcards have a higher precedence. If no match
based on IP and port occurs at all,the “main” server configuration is
used.

If multiple virtual hosts contain the best matching IP address and
port,the server selects from these virtual hosts the best match based
on the requested hostname. If no matching name-based virtual host is
found,then the first listed virtual host that matched the IP address
will be used. As a consequence,the first listed virtual host for a
given IP address and port combination is the default virtual host for
that IP and port combination.

这基本意味着在httpd.conf中遇到的第一个VirtualHost将被用作默认值,或者如果所有虚拟主机都在单独的(包含的).conf文件中(可能是您的情况),那么从字母顺序第一个.conf文件中的那个将是用过的.

TLDR:尝试将包含example.com虚拟主机的.conf文件重命名为aaa.conf(并重启httpd)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读