【问题标题】:VIrtualHost: Different hosts point to the same locationVIrtualHost:不同的主机指向同一个位置
【发布时间】:2012-07-09 06:27:46
【问题描述】:

我正在尝试为两个 Zend Framework 应用程序设置虚拟主机。我首先更改了system32 hosts 文件。

它现在包含以下几行:

127.0.0.1           localhost
#   ::1             localhost
127.0.0.1           quickstart

之后,我继续更改httpd-vhosts.conf 文件。其当前内容:

<VirtualHost *:80>
    ServerAdmin postmaster@dummy-host2.localhost
    DocumentRoot "G:\workspace\Andrew\ProjManer\public"
    ServerName localhost
    ServerAlias localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" combined
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin postmaster@dummy-host2.localhost
    DocumentRoot "G:\workspace\Andrew\quickstart\public"
    ServerName quickstart
    ServerAlias quickstart
    ErrorLog "logs/quickstart-error.log"
    CustomLog "logs/quickstart-access.log" combined
</VirtualHost>

如果我不先用 localhost 添加虚拟主机,我会得到一个"Access forbidden 403 Error message"
现在的问题是两者都指向同一个位置,即本地主机。我应该如何让第二个虚拟主机工作?我也使用了flushdns

【问题讨论】:

  • 在 Apache 主配置文件中是否有这样的一行:NameVirtualHost *:80?如果没有尝试添加它
  • @TimFountain 我可以把它放在httpd-vhosts.conf吗?

标签: apache zend-framework virtualhost


【解决方案1】:

您不需要其中的 ServerAlias,除非您想通过 q​​uickstart2 进入快速入门。在这种情况下,您将执行 ServerAlias quickstart2。您被禁止访问,因为您的 httpd.conf 中的文档根目录没有 index.php 或者虚拟主机没有 index.php 并且您设置了 -Indexes

除了虚拟主机和主机文件看起来不错。尝试重新启动浏览器并重新启动 apache。

【讨论】:

  • 让我看看我是否理解得很好。 httpd.conf 中的文档根目录具有本地主机的路径。第二个主机名的虚拟主机有一个 index.php。本地主机现在正在工作,但新主机有一条访问禁止消息。
  • 好的解决了。我在 httpd.conf 中添加了一个目录标签
  • 我的 localhost 在我的 httpd.conf 中,我的 vhost 文件包含我放入 hosts 文件中的不同主机的附加条目。我保持我的虚拟主机简单,只设置 DocumentRoot 和 ServerName(我真的应该做日志以减少混乱并保持主日志文件干净)。您还可以将目录标签放在虚拟主机 btw
猜你喜欢
  • 2014-07-06
  • 2013-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-02
  • 2014-02-28
  • 1970-01-01
  • 2021-06-01
相关资源
最近更新 更多