【问题标题】:xampp virtual host - always loading htdocsxampp 虚拟主机 - 始终加载 htdocs
【发布时间】:2013-07-14 09:42:59
【问题描述】:

我正在尝试在我的本地主机 (XAMPP) 上创建一个虚拟主机。尝试了所有组合,但我总是加载 htdocs 而不是特定文件夹

这是hosts 文件:

127.0.0.1 localhost
::1 localhost
127.0.0.1 devsnappy

这里是httpd-vhosts.conf

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot E:/xampp/htdocs/snappy/public
    ServerName devsnappy
    <Directory "E:/xampp/htdocs/snappy/public">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

有什么建议吗?

【问题讨论】:

  • 你正确重启httpd了吗?

标签: apache xampp localhost vhosts


【解决方案1】:
  1. 不要使用 .DEV,注册表现在归 Google 所有,它会强制您的 Chrome 使用 SSL (443)。试试 .app 或 .lan。

  2. 确保您的浏览器未加载 HTTPS(端口 443),而 Apache 仅在 80 端口上获取连接,例如

【讨论】:

    【解决方案2】:

    对于阅读本文但没有任何解决方案可以帮助您的任何人,这对我有帮助。

    只需在您的 httpd.conf 中取消注释此 Include 行:

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

    这样,您在 etc/extra/httpd-vhosts.conf 中所做的更改就会可用!

    之后别忘了重启 Apache 服务器!

    【讨论】:

    • 拯救了我的一天。谢谢
    • 天哪,浪费了我宝贵的 1 个小时来摆弄 httpd-vhosts.conf 文件,终于发现它在 httpd.conf 中被注释了,感谢您指出这一点!
    【解决方案3】:

    这是一个 guide 将 vhost 添加到 xampp

    您似乎遗漏了 hosts 文件中的某些内容。

    例如,假设您有另一个客户 B 的网站。您将在 hosts 文件中添加 127.0.0.1 clientB.local >,然后 C:\xampp\apache\conf\extra\httpd-vhosts.conf 将如下所示:

    NameVirtualHost *
      <VirtualHost *>
        DocumentRoot "C:\xampp\htdocs"
        ServerName localhost
      </VirtualHost>
      <VirtualHost *>
        DocumentRoot "C:\Documents and Settings\Me\My Documents\clientA\website"
        ServerName clientA.local
      <Directory "C:\Documents and Settings\Me\My Documents\clientA\website">
        Order allow,deny
        Allow from all
      </Directory>
    </VirtualHost>
    <VirtualHost *>
        DocumentRoot "C:\Documents and Settings\Me\My Documents\clientB\website"
        ServerName clientB.local
      <Directory "C:\Documents and Settings\Me\My Documents\clientB\website">
        Order allow,deny
        Allow from all
      </Directory>
    </VirtualHost>
    

    然后重启 httpd

    【讨论】:

    • 我认为这与hosts 文件无关。更好的猜测是他只是在修改httdp-vhosts.conf后忘记重启apache服务器。
    • 我复制粘贴了指南中的示例...更改了路径...重新启动并工作...然后改回我的自定义虚拟主机名...重新启动并工作...我愿意不完全是 pb 是什么(本指南是我做的第一个指南),但如果有人和我有相同的 pb,那么遵循这个答案可能会有所帮助......谢谢大家
    • +1 - 对不起,我错了,我以为你在谈论 /etc/hosts 文件。
    • 也为我工作。 +1 修复 :)
    • 很抱歉,该指南链接已损坏,您能更新一下吗?
    【解决方案4】:

    哦,在 Apache 2.4.9 中让它工作对我来说真的很痛苦。我找到了很多教程,但我无法让它工作。

    我的解决方案适用于 APACHE 2.4 及更高版本。我已经使用 Apache 2.4.9 对其进行了测试

    您需要编辑两个文件。请在进行更改之前备份这两个文件。如果您写错任何内容,即使您卸载 xampp 然后再次安装 xampp,您的本地主机也将无法工作。

    第 1 步:

    编辑这个文件

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

    使用记事本中的“以管理员身份运行”打开此文件(非常重要)。您可以这样做

    开始菜单>记事本>右键单击>以管理员身份运行>打开文件

    在文件末尾添加这两行

    127.0.0.1       testsite.dev
    127.0.0.1       www.testsite.dev
    

    无论你去 testsite.dev 还是 www.testsite.dev ,它现在都会尝试从你的本地机器而不是从网络访问

    第 2 步:

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

    您可以正常编辑此文件,无需以“以管理员身份运行”运行此文件 在此文件末尾添加以下行

    NameVirtualHost *:80
    <VirtualHost *:80> 
        DocumentRoot "E:/xampp/htdocs"
        ServerName localhost
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerAdmin admin@.testsite.dev
        DocumentRoot "E:/xampp/htdocs/htc"
        ServerName testsite.dev
        ServerAlias www.testsite.dev
    </VirtualHost>
    

    我在E盘设置了我的xampp,所以当你从这里复制时,请确保根据你的xampp安装进行更改。最后一部分有点有趣。我指出这个药水

    <VirtualHost *:80>
        ServerAdmin admin@.testsite.dev
        DocumentRoot "E:/xampp/htdocs/htc"
        ServerName testsite.dev
        ServerAlias www.testsite.dev
    </VirtualHost>
    

    您在哪里可以找到此代码?在互联网上,您可以在很多地方找到它,但可能对您不起作用,因为该代码会与您的 Apache 版本不同。那么解决方案是什么?

    在文件的末尾,您会看到已经有一些注释行向您展示了如何设置虚拟主机的演示,只需复制这些行并进行必要的更改,它就会为您工作。我附上了截图更好的理解

    http://postimg.org/image/5pug9f42p/

    【讨论】:

      猜你喜欢
      • 2013-05-16
      • 2013-08-09
      • 2021-02-10
      • 2015-09-24
      • 2017-01-26
      • 2020-12-17
      • 2019-06-11
      • 2011-04-26
      • 2015-06-24
      相关资源
      最近更新 更多