【问题标题】:How can I get virtual host to work with XAMPP?如何让虚拟主机与 XAMPP 一起工作?
【发布时间】:2018-04-16 19:59:06
【问题描述】:

我昨天刚刚在我的 Win 7 机器上重新安装了 XAMPP。我正在做一个 Laravel 项目。我安装了当前版本的 Laravel,然后我去在本地机器上设置虚拟主机。当我转到我设置的 url (jrd_dnd_tools.localhost) 时,我收到一条 Bad Gateway 消息我以前设置过虚拟主机,但不知道为什么会这样。我确定我错过了一些愚蠢的东西,但不知道是什么。

httpd-vhosts.conf

<VirtualHost *:80>
     ServerAdmin webmaster@jrd_dnd_tools.localhost
     DocumentRoot "C:\Users\Joey\Web\jrd_dnd_tools/public"
     ServerName jrd_dnd_tools.localhost
     ServerAlias www.jrd_dnd_tools.localhost
     ErrorLog "logs/jrd_dnd_tools.localhost.log"
     CustomLog "logs/jrd_dnd_tools.localhost.log" common
     <Directory "C:\Users\Joey\Web\jrd_dnd_tools/public">
          AllowOverride All
          Order Allow,Deny
          Allow from all

          ## --New way of doing it
          Require all granted
     </Directory>
</VirtualHost>

.hosts

127.0.0.1       localhost
::1             localhost
::1             database.localhost
127.0.0.1       jrd_dnd_tools.localhost

【问题讨论】:

  • 可能duplicate
  • 我知道它看起来可能是重复的,但我已经搜索了 Stack Exchange 和 Google,但没有找到似乎可以解决问题的答案
  • C:\Users\Joey\Web\jrd_dnd_tools/public - 你正在混合正斜杠和反斜杠,DocumentRoot&lt;Directory&gt;。不确定这是否会导致“错误网关”,但这肯定是错误的 - 尝试修复所有反斜杠。
  • 还要检查您的错误日志以获取更多详细信息。
  • 如果您使用代理,请检查您的浏览器配置并使用您需要使用的本地名称提供“no use proxy for...”(并将 www... 别名添加到您的主机文件也)。

标签: apache xampp virtualhost


【解决方案1】:

你弄错了*:80,因为虚拟主机从不使用通配符。相反,您可以使用jrd_dnd_tools.localhost。下面是我的虚拟主机设置,我为演示做了。

还要注意我在文档根目录和目录中的目录分隔符。

进行这 2 项更改,您的虚拟主机将像魅力一样工作。

<VirtualHost t.com:80>
    ServerAdmin webmaster@t.com
     DocumentRoot "C:/xampp/htdocs/t"
     ServerName t.com
     ServerAlias t.com
     ## ErrorLog "logs/jrd_dnd_tools.localhost.log"
     ##CustomLog "logs/jrd_dnd_tools.localhost.log" common
     <Directory "C:/xampp/htdocs/t">
          AllowOverride All
          Order Allow,Deny
          Allow from all

          ## --New way of doing it
          Require all granted
     </Directory>
</VirtualHost>

【讨论】:

  • 我是这样设置的,但现在我收到了错误的请求错误。
  • @JoeyD473 - 我希望您也对.hosts 文件进行了更改。喜欢127.0.0.1 t.com
  • 我的hosts文件和原文件一样
猜你喜欢
  • 2016-11-27
  • 2013-09-11
  • 2011-02-02
  • 2016-07-19
  • 2014-07-14
  • 2012-06-08
  • 2017-04-16
  • 2015-04-29
  • 2021-02-10
相关资源
最近更新 更多