无法访问此站点 - XAMPP 忽略自定义域虚拟主机

This site can’t be reached - XAMPP ignores custom domain vhosts

环境

配置

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

127.0.0.1 www.test.local test.local

C:\xampp\apache\conf\httpd.conf:

DocumentRoot "D:/htdocs"
<Directory "D:/htdocs">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
</Directory>

C:\xampp\apache\conf\extra\httpd-vhosts.conf:

<VirtualHost *:80>
    DocumentRoot D:/htdocs
    ServerName localhost
    <Directory "D:/htdocs">
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot D:/htdocs
    ServerName test.local
    <Directory "D:/htdocs">
        Allow from all
    </Directory>
</VirtualHost>

问题

当我启动 Apache 并访问 localhost 时就可以了。当我尝试访问 test.local 时出现问题:浏览器 returns 一条 无法访问此站点 消息。这就像 XAMPP 忽略定义到 httpd-vhost.conf 文件中的自定义域虚拟主机。服务器关闭时显示相同的消息。

This site can’t be reached 
The webpage at http://test.local/ might be temporarily down or it may have moved permanently to a new web address.
ERR_ADDRESS_INVALID

几天前设置工作正常,我所做的唯一更改是新软件安装。我的意思是,Apache 配置文件没有变化。

您是否使用这样的映射更新了您的 C:\Windows\System32\drivers\etc\hosts 文件?

  • 将此行添加到 hosts 文件的末尾
127.0.0.1 test.local
  • localhost 域在没有此映射的情况下工作,因为 OS 已经将 "localhost" 识别为环回 IP 地址的内置别名

(此建议假设您 运行 并在同一台本地计算机上进行测试)

如果您之前所有的堆栈都正常工作,请不要像我一样 不要忘记检查某些浏览器扩展是否阻止了您的本地流量,例如某些扩展与防病毒系统有关。

在我的例子中,它是 Kaspersky Protection 扩展。当出现问题时,它会显示以下图形。

C:\Windows\System32\drivers\etc

127.0.0.1   test.local

C:\xampp\apache\conf\extra\httpd-vhosts.conf:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "C:/wamp64/www/test"
    ServerName test.local
    <Directory "C:/wamp64/www/hydroboost/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local
  </Directory>
</VirtualHost>