Apache Snow Leopard 上的多个主机出现问题

发布于 2024-10-21 12:33:48 字数 1108 浏览 7 评论 0原文

我在 Mac OS X (Snow Leopard) 机器上运行 Apache。我希望能够设置多个主机名,以便我可以同时开发和测试多个站点,但我似乎无法让它工作。

这是我尝试过的:

在我的 etc/hosts 文件中,我设置添加了这些条目:

127.0.0.1    testsite1.localdev.com
127.0.0.1    testsite2.localdev.com

然后,在 apache2/httpd.conf 中,我添加了这些条目:

<VirtualHost *:80>
   DocumentRoot /Library/WebServer/Documents/www/development/testsite1
   ServerName testsite1.localdev.com
   <Directory "/Library/WebServer/Documents/www/development/testsite1">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot /Library/WebServer/Documents/www/development/testsite2
   ServerName testsite2.localdev.com
   <Directory "/Library/WebServer/Documents/www/development/testsite2">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

但发生的情况是,两个主机名都解析为 httpd 中列出的第一个主机名.conf 文件——在本例中为 testsite1。如果我交换他们的位置,那么他们都会解析为 testsite2。

我还尝试更改读取 *:80 的区域并将其替换为每个站点的特定主机名,但这没有效果。

我确信每次更改后都会重新启动 apache。

感谢您的帮助!

加里

I am running Apache on my Mac OS X (Snow Leopard) machine. I want to be able to set up multiple hostnames so that I can develop and test multiple sites at the same time, but I can't seem to get this to work.

Here's what I've tried:

In my etc/hosts file I've set added these entries:

127.0.0.1    testsite1.localdev.com
127.0.0.1    testsite2.localdev.com

Then, in apache2/httpd.conf I have added these entries:

<VirtualHost *:80>
   DocumentRoot /Library/WebServer/Documents/www/development/testsite1
   ServerName testsite1.localdev.com
   <Directory "/Library/WebServer/Documents/www/development/testsite1">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot /Library/WebServer/Documents/www/development/testsite2
   ServerName testsite2.localdev.com
   <Directory "/Library/WebServer/Documents/www/development/testsite2">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

But happens is that both hostnames resolve to the first one listed in the httpd.conf file -- in this case, testsite1. If I switch their positions, then they both resolve to testsite2.

I've also tried changing the area that reads *:80 and replacing that with the specific hostnames for each site, but that has no effect.

I am being sure to reboot apache after each change.

Thanks for any help!

Gary

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

网白 2024-10-28 12:33:48
  • 在 /etc/apache2/httpd.conf 中取消注释 vhost 文件,例如:

    # 虚拟主机
    包括/private/etc/apache2/extra/httpd-vhosts.conf
    
  • 在 /private/etc/apache2/extra/httpd-vhosts.conf 中使用...

    <前><代码>#
    # 使用基于名称的虚拟主机。
    #
    名称虚拟主机 *:80

    <虚拟主机 *:80>
    文档根目录“/Library/WebServer/Documents”
    服务器名称 localhost

    # 本地测试站点
    <虚拟主机 *:80>
    <目录/Users//Sites/test>
    允许覆盖全部

    DocumentRoot“/Users//Sites/test”
    服务器名称 test.local

  • 确保您的 和 Sites 文件夹具有 755 的权限

,并确保添加到 /etc/hosts 文件中...

# test
127.0.0.1   test.local
  • in /etc/apache2/httpd.conf uncomment the vhost file like:

    # Virtual hosts
    Include /private/etc/apache2/extra/httpd-vhosts.conf
    
  • in /private/etc/apache2/extra/httpd-vhosts.conf use...

    #
    # Use name-based virtual hosting.
    #
    NameVirtualHost *:80
    
    <VirtualHost *:80>
        DocumentRoot "/Library/WebServer/Documents"
        ServerName localhost
    </VirtualHost>
    
    # local test site
    <VirtualHost *:80> 
      <Directory /Users/<youruser>/Sites/test>
        AllowOverride All 
      </Directory> 
      DocumentRoot "/Users/<youruser>/Sites/test"
      ServerName test.local
    </VirtualHost>
    
  • Be sure that your and Sites folders have permissions of 755

and be sure that you add to your /etc/hosts file...

# test
127.0.0.1   test.local
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文