MAC OS X:MAMP环境与虚拟主机
我不知道这里发生了什么,但我在Mac OS X上运行甲基苯丙胺1.9在我的httpd.conf文件,DocumentRoot的设置为默认的htdocs目录路径。在htdocs文件夹中,我创建了一些“子网站”,以便将它们设置为虚拟主机....我可以访问指定的路径,但它们似乎都默认为我设置的第一个路径。MAC OS X:MAMP环境与虚拟主机
实质上,我配置的第一个虚拟主机是为site1.localhost.com。我自从配置了site2.localhost.com和site3.localhost.com。但是,转到最后两个地址中的任何一个,总是会将我重定向到site1.localhost.com。此外,去localhost.com:8888也只是拉起site1.localhost.com。我不知道我在哪里犯了一个错误的步骤,但希望这里的某个人能够帮助我找出问题......哦,并且在重新启动apache等之后,对/ etc /主机或httpd.conf文件。
在我的httpd.conf文件(相关部分,反正...):
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
# MAMP DOCUMENT_ROOT !! Don't remove this line !!
DocumentRoot "/Applications/MAMP/htdocs"
#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/Applications/MAMP/htdocs">
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs/site1/"
ServerName site1.localhost.com
</VirtualHost>
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs/sub/site2/"
ServerName site2.localhost.com
</VirtualHost>
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs/sub/site3/"
ServerName site3.localhost.com
</VirtualHost>
在我的/ etc/hosts文件:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 site1.localhost.com
127.0.0.1 site2.localhost.com
127.0.0.1 site3.localhost.com
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
在你的httpd.conf文件中找到以下行,并删除注释(#):
# NameVirtualHost *
除了MattLeff的回答,您还应该添加服务器别名,只要是安全的:
ServerAlias www.website.dev
如果不这样做,你的浏览器自动地补充说:(!和隐藏它,RAWR)的“http // WWW”,那么你的环境中会自动默认为第一个虚拟主机。
我可以看到你有你的答案。在我的情况下是不够的。当我添加Chords的建议时,我能够获得localhost +许多其他虚拟主机(demo.client.com)在我的MAMP上工作。它只在将本地主机添加为列表顶部的虚拟主机时起作用。
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/Applications/MAMP/htdocs/clientA/"
ServerName clientA.local
ErrorLog "logs/clientA-local-error_log"
CustomLog "logs/clientA-local-access_log" common
</VirtualHost>
啊啊啊谢谢!它让我疯狂! – locrizak 2011-06-18 19:56:48