Apache HTTP Server 2.4.41 提供令人困惑的虚拟主机页面服务

Apache HTTP Server 2.4.41 提供令人困惑的虚拟主机页面服务

我的httpd-vhosts.conf样子是这样的:

<VirtualHost *:80>
    DocumentRoot "C:/Apache24/htdocs/rodde.net"
    ServerName rodde.net
    ServerAlias www.rodde.net
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/Apache24/htdocs/coderodde.net"
    ServerName coderodde.net
    ServerAlias wwww.coderodde.net
</VirtualHost>

我的C:Windows\System32\drivers\etc\hosts包含:

127.0.0.1 localhost
127.0.0.1 www.coderodde.net
127.0.0.1 www.rodde.net
127.0.0.1 rodde.net
127.0.0.1 coderodde.net

我的C:\Apache24\htdocs\rodde.net\index.html包含:

<html>
<body>
<h1>
rodde.net works!
</h1>
</body>
</html>

我的C:/Apache24/htdocs/coderodde.net/index.html包含:

<html>
<body>
<h1>
coderodde.net works!
</h1>
</body>
</html>

我的C:/Apache24/htdocs/index.html包含:

<html>
<body>
<h1>Apache HTTP Server 2.4.41 works!</h1>
</body>
</html>

最后,httpd.exe -S

C:\Apache24\bin>httpd -S
VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server rodde.net (C:/Apache24/conf/extra/httpd-vhosts.conf:23)
         port 80 namevhost rodde.net (C:/Apache24/conf/extra/httpd-vhosts.conf:23)
                 alias www.rodde.net
         port 80 namevhost coderodde.net (C:/Apache24/conf/extra/httpd-vhosts.conf:29)
                 alias wwww.coderodde.net
ServerRoot: "C:/Apache24"
Main DocumentRoot: "C:/Apache24/htdocs"
Main ErrorLog: "C:/Apache24/logs/error.log"
Mutex default: dir="C:/Apache24/logs/" mechanism=default
PidFile: "C:/Apache24/logs/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: SRVROOT=c:/Apache24

我的问题是这样的:'

  1. 当我访问rodde.net或时www.rodde.net,我看到了文字rodde.net 有效!,我应该这么做。
  2. 当我访问时coderodde.net,我看到了文字coderodde.net 有效!,我应该这么做。
  3. 然而,当我访问www.coderodde.net或时localhost,我看到了文字rodde.net 有效!

答案1

default server rodde.net (C:/Apache24/conf/extra/httpd-vhosts.conf:23)

这是您的默认服务器,即默认虚拟主机。每当没有匹配的显式ServerName或时,都会使用它ServerAlias。例如,当您访问时就是这种情况http://localhost

port 80 namevhost coderodde.net (C:/Apache24/conf/extra/httpd-vhosts.conf:29)
        alias wwww.coderodde.net

该虚拟主机有两个名称:coderodde.netwwww.coderodde.net,其中四个这就是为什么它不会www.coderodde.net与三个 w 匹配,而是使用默认虚拟主机。这叫做拼写错误

相关内容