XAMPP 虚拟主机不工作

XAMPP Virtual Hosts not working

在将其标记为已回答之前,请阅读整篇文章,因为是的,这些问题有很多,但 NONE 的答案在全部.

在过去的 6 个月里,我在这里和网络上查看了大约 50 个不同的表单帖子,试图让我的 XAMPP 虚拟主机正常工作。

主机文件

127.0.0.1       localhost
127.0.0.1       vws.localhost
127.0.0.1       instancegaming.net
127.0.0.1       vws.instancegaming.net

http-vhosts 文件(7 月 26 日更新)

 # Virtual Hosts
 #
 # Required modules: mod_log_config

 # If you want to maintain multiple domains/hostnames on your
 # machine you can setup VirtualHost containers for them. Most      configurations
 # use only name-based virtual hosts so the server doesn't need to worry    about
 # IP addresses. This is indicated by the asterisks in the directives below.
 #
 # Please see the documentation at
 # <URL:http://httpd.apache.org/docs/2.4/vhosts/>
 # for further details before you try to setup virtual hosts.
 #
 # You may use the command line option '-S' to verify your virtual host
 # configuration.

 #
 # Use name-based virtual hosting.
 #
 # NameVirtualHost *:80
 #
 # VirtualHost example:
 # Almost any Apache directive may go into a VirtualHost container.
 # The first VirtualHost section is used for all requests that do not
 # match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
 #
 <VirtualHost *:80>
    ServerName localhost
    DocumentRoot "C:\xampp\htdocs"
    <Directory "C:\xampp\htdocs">
      DirectoryIndex index.php
    </Directory>
 </VirtualHost>

我不知所措,我试过将所有字段放入本地主机,然后放入 instancegaming.net,但似乎没有任何效果。我已阅读 Apache 日志,发现只有 SSL 错误。

当我尝试访问 [http://] vws.localhost、vws.192.168.0.47、vws.instancegaming.net 时,所有这些都在 chrome 中给出相同的错误:

ERR_NAME_NOT_RESOLVED

然后我尝试清空 chrome 的主机缓存,但这也无济于事。 旁注:我重新安装了 XAMPP 4 次,试图让它工作。

如果您在 windows 环境中(7 和 10 测试)XAMPP,请按照以下步骤操作:

  1. 在主机文件中添加 [C:\Windows\System32\drivers\etc]
127.0.0.1       vws.localhost
127.0.0.1       instancegaming.net
127.0.0.1       vws.instancegaming.net
  1. 将此添加到 httpd.conf [C:\__Server\apache\conf] 中。 虽然有人说这有安全风险,但没有这个就找不到办法
<Directory />
    AllowOverride none
    Require all granted
</Directory>
  1. 在 httpd-vhosts.conf 添加这些 [C:\__Server\apache\conf\extra]
<VirtualHost *:80>
     ServerName localhost
     DocumentRoot "C:\__Server\htdocs"
     <Directory "C:\__Server\htdocs">
         DirectoryIndex index.php
     </Directory>
 </VirtualHost>

<VirtualHost *:80>
     ServerName tools.com.at
     DocumentRoot "E:\phpStorms\git\tools-class"
     SetEnv APPLICATION_ENV "development"
     <Directory "E:\phpStorms\git\tools-class">
         DirectoryIndex index.php
         AllowOverride All
         Order allow,deny
         Allow from all        
     </Directory>
 </VirtualHost>
 
 <VirtualHost *:80>
     ServerName laravel.test.com.at
     DocumentRoot "E:\laravel.test.com.at\public"
     SetEnv APPLICATION_ENV "development"
     <Directory "E:\laravel.test.com.at\public">
         DirectoryIndex index.php
         AllowOverride All
         Order allow,deny
         Allow from all
     </Directory>
 </VirtualHost>

这个

的模板
<VirtualHost *:80>
     ServerName nameInHostsFile
     DocumentRoot "pathOfTheWindowsFileLocationWhichWillBeDocumentRoot"
     SetEnv APPLICATION_ENV "development"
     <Directory "pathOfTheWindowsFileLocationWhichWillBeDocumentRoot">
         DirectoryIndex index.php
         AllowOverride All
         Order allow,deny
         Allow from all      
     </Directory>
 </VirtualHost>

注 1:我的 xampp 安装在 C:\__Server 位置

注意 2:我的文件夹名称是 laravel.test.com.at 并且它在 E: 驱动器 E:\laravel.test.com.at

注意3:总是从windows资源管理器中的地址栏复制文件夹位置,所以不会出错。

注意4:每次编辑httpd-vhosts.conf后必须重启XAMPP.

注5:在url[即com.at]中使用不常见的部分,这样它是唯一的,解析dns没有问题。

更新:疑难解答@Jacob Jewett

全新拷贝XAMPP安装在C盘后-

  1. 只是 add/append httpd-vhosts.conf 文件中的这些行
<VirtualHost *:80>
     ServerName localhost
     DocumentRoot "C:\xampp\htdocs"
     <Directory "C:\xampp\htdocs">
         DirectoryIndex index.php
     </Directory>
 </VirtualHost>

<VirtualHost *:80>
     ServerName vws.localhost
     DocumentRoot "C:\xampp\vws"
     SetEnv APPLICATION_ENV "development"
     <Directory "C:\xampp\vws">
         DirectoryIndex index.php
         AllowOverride All
         Order allow,deny
         Allow from all        
     </Directory>
 </VirtualHost>
  1. 将其添加到 httpd.conf 文件中
<Directory />
    AllowOverride none
    Require all granted
</Directory>
  1. 为 php [C:\xampp\php] 添加 PATH 变量,并检查 [=] 中是否没有另一个 php 路径23=]变量。

  2. 重启xampp并浏览localhost

我发现有效的答案是在主机文件中。

192.168.0.47        localhost somthing.instancegaming.net      

我想在这里补充一件事:对于任何确定一切设置正确的人,请确保不要在主机文件的别名字符串中使用任何下划线;由于某种原因,它不能接受下划线。

我有类似的问题,vhosts 不工作。但就我而言,我发现主机文件存在权限问题。希望这对某些人有所帮助。 hosts file ignored, how to troubleshoot?

如果 ping 成功但虚拟主机无法使用 XAMPP 7.3.1 和 Windows 10 Pro,则问题可能是万维网发布服务受到干扰。

在我的系统上,Apache 和 MySQL 成功启动,但虚拟主机无法浏览,直到我停止 WWWPS 服务(在 Windows 服务中)。然后虚拟主机立即可用。当 WWWPS 再次启动时它立即停止工作。

另外确保行

Include etc/extra/httpd-vhosts.conf

未在httpd.conf

中引用