在 Apache 上设置虚拟主机 (XAMPP, Windows 10)

Set up virtual hosts on Apache (XAMPP, Windows 10)

我尝试使用 XAMPP 为一些本地站点设置虚拟主机。

我执行了后续步骤:

  1. 在"C:/xampp/apache/conf/extra/httpd-vhosts.conf"中我添加了:
<VirtualHost *:8081>
    DocumentRoot "C:/xampp/htdocs/"
    ServerName localhost
</VirtualHost>
<VirtualHost *:8081>
    DocumentRoot C:/xampp/htdocs/fw/public
    ServerName fw.local.com
    <Directory "C:/xampp/htdocs/fw/public">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
  1. 里面 "C:/Windows/System32/drivers/etc/hosts" 我补充说:
127.0.0.1       localhost    
127.0.0.1       fw.local.com
  1. 重新启动 Apache。

还有...

如果我关注:

http://localhost:8081/

一切正常:我在文件夹 "htdocs" 中看到我的目录和项目。

但是!如果我遵循:

http://fw.local.com/

我希望在“..htdocs/fw/public”中看到我的 "index.php" 文件的结果。但我得到:

This site can’t be reached
fw.local.com refused to connect.

文件 "C:/xampp/apache/conf/httpd.conf" 包含:

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

我哪里错了?

您应该将:<VirtualHost *:8081> 更改为 <VirtualHost *:80>,fw.local.com 尝试连接到端口 80,而不是 8081。

编辑: 您也可以保持原样并连接到:http://fw.local.com:8081/