Apache Snow Leopard 上的多个主机出现问题
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 /etc/apache2/httpd.conf 中取消注释 vhost 文件,例如:
在 /private/etc/apache2/extra/httpd-vhosts.conf 中使用...
<前><代码>#
# 使用基于名称的虚拟主机。
#
名称虚拟主机 *:80
<虚拟主机 *:80>
文档根目录“/Library/WebServer/Documents”
服务器名称 localhost
# 本地测试站点/Sites/test>
/Sites/test”
<虚拟主机 *:80>
<目录/Users/
允许覆盖全部
DocumentRoot“/Users/
服务器名称 test.local
确保您的 和 Sites 文件夹具有 755 的权限
,并确保添加到 /etc/hosts 文件中...
in /etc/apache2/httpd.conf uncomment the vhost file like:
in /private/etc/apache2/extra/httpd-vhosts.conf use...
Be sure that your and Sites folders have permissions of 755
and be sure that you add to your /etc/hosts file...