虚拟主机的行为非常奇怪

虚拟主机的行为非常奇怪

我有两个域名mycommunitysite.commypersonalblog.com

当我转到 时mypersonalblog.com,一切正常。当我转到 时mycommunitysite.com,它也会转到首页mypersonalblog.com。如果我转到,它会按预期mycommunitysite.com/forum转到 的论坛子目录。mycommunitysite.com

apache 中的虚拟主机指令如下所示,我的服务器运行的是 CentOS,如果这有区别的话:

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/mycommunitysite
    ServerName mycommunitysite.com
    ServerAlias www.mycommunitysite.com
    ErrorLog logs/mycommunitysite.com
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/mypersonalblog
    ServerName mypersonalblog.com
    ServerAlias www.mypersonalblog.com
    ErrorLog logs/mypersonalblog.com
</VirtualHost>

输出apachectl -S

httpd: Could not reliably determine the server's fully qualified domain name, using 108.166.78.198 for ServerName
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server myweddingsite.com (/etc/httpd/conf/httpd.conf:1015)
         port 80 namevhost myweddingsite.com (/etc/httpd/conf/httpd.conf:1015)
         port 80 namevhost clientsite.com (/etc/httpd/conf/httpd.conf:1025)
         port 80 namevhost mycommunitysite.com (/etc/httpd/conf/httpd.conf:1035)
         port 80 namevhost mypersonalblog.com (/etc/httpd/conf/httpd.conf:1053)
Syntax OK

答案1

添加全局指令ServerName www.example.comhttpd.conf
确保您的 DNS 对所有域名和 IP 的正向和反向查找均能正常工作。

答案2

如果/etc/hosts缺少 Apache 尝试绑定的 IP 条目,它会抱怨无法确定 FQDN。这似乎会影响 VirtualHosts。

相关内容