- 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>
希望我已经解释得很好……
谢谢!
解决方法
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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。