一切运行正常,但问题是当我尝试通过服务器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文件中的那个将是用过的.