Categories
Mastering Development System & Network

Apache HTTP Server 2.4.41 is confusingly serving virtual host pages

My httpd-vhosts.conf looks like this:

<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>

My C:Windows\System32\drivers\etc\hosts contains:

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

My C:\Apache24\htdocs\rodde.net\index.html contains:

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

My C:/Apache24/htdocs/coderodde.net/index.html contains:

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

My C:/Apache24/htdocs/index.html contains:

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

Finally, 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

My problem is this: ‘

  1. When I visit rodde.netor www.rodde.net, I see the text rodde.net works!, as I should.
  2. When I visit coderodde.net, I see the text coderodde.net works!, as I should.
  3. However, when I visit www.coderodde.net or localhost, I see the text rodde.net works!.

Leave a Reply

Your email address will not be published. Required fields are marked *