我的vhosts是:
# for localhost to work properly
<VirtualHost *:1983>
ServerAdmin admin@localhost
DocumentRoot "d:/wamp/www"
ServerName localhost
</VirtualHost>
# - See more at: http://yogeshchaugule.com/blog/2014/how-setup-virtual-hosts-wamp#sthash.zVhOHBlJ.dpuf
# - @: http://www.techrepublic.com/blog/smb-technologist/create-virtual-hosts-in-a-wamp-server/
# - @: http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp (maybe out of usable scope)
# afm : Agile Farm Manager
#<VirtualHost *:1983>
# DocumentRoot "D:/projects/afm/Code"
# ServerName dafm.dev
# <Directory "D:/projects/afm/Code">
# Order allow,deny
# Allow from all
# AllowOverride All
# </Directory>
#</VirtualHost>
# mrs : Meeting Request System
<VirtualHost mrs.dev:1983>
DocumentRoot "D:/wamp/www/mrs_site/mrs"
ServerName mrs.dev
ServerAlias mrs.dev
<Directory "D:/wamp/www/mrs_site/mrs">
Order allow,deny
Allow from all
AllowOverride All
</Directory>
</VirtualHost>
# dtk : Kit Designer
<VirtualHost dtk.dev:1983>
DocumentRoot "D:/wamp/www/designertoolkit/"
ServerName dtk.dev
ServerAlias dtk.dev
<Directory "D:/wamp/www/designertoolkit/">
Order allow,deny
Allow from all
AllowOverride All
</Directory>
</VirtualHost>
我的windows'host文件有以下映射
#VIRTUAL DOMAINS
127.0.0.1 dafm.dev
127.0.0.1 mrs.dev
127.0.0.1 dtk.dev
我配置的端口是:1983所以我访问wamp:http://localhost:1983/
或http://mrs.dev:1983/
转到我当前的项目。但我的其他项目不再可访问了。
当我转到dtk.dev:1983/
时,会为每个有效的服务请求转到同一个项目http://mrs.dev:1983/
。
我需要同时在WAMP上运行多个项目。虚拟主机有什么问题?
请帮助
答案 0 :(得分:2)
您需要使用NameVirtualHost。请参阅Apache手册:http://httpd.apache.org/docs/current/vhosts/name-based.html
像这样:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>
也许这有效:
NameVirtualHost *:1983
# for localhost to work properly
<VirtualHost *:1983>
ServerAdmin admin@localhost
DocumentRoot "d:/wamp/www"
ServerName localhost
</VirtualHost>
# mrs : Meeting Request System
<VirtualHost *:1983>
DocumentRoot "D:/wamp/www/mrs_site/mrs"
ServerName mrs.dev
ServerAlias mrs.dev
</VirtualHost>
# dtk : Kit Designer
<VirtualHost *:1983>
DocumentRoot "D:/wamp/www/designertoolkit/"
ServerName dtk.dev
ServerAlias dtk.dev
</VirtualHost>
<Directory "D:/wamp/www/designertoolkit/">
Order allow,deny
Allow from all
AllowOverride All
</Directory>
<Directory "D:/wamp/www/mrs_site/mrs">
Order allow,deny
Allow from all
AllowOverride All
</Directory>
答案 1 :(得分:-3)
感谢匿名@ user4311956的回答指出NameVirtualHost
指令很重要。
但是根据我自己的测试,我发现如果我在每个虚拟主机之前提到NameVirtualHost
指令我创建它是有效的,否则就失败了。
此处httpd-vhosts.conf
文件的代码实现了神奇:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:1983
# for localhost to work properly
<VirtualHost *:1983>
ServerAdmin admin@localhost
DocumentRoot "d:/wamp/www"
ServerName localhost
</VirtualHost>
# - See more at: http://yogeshchaugule.com/blog/2014/how-setup-virtual-hosts-wamp#sthash.zVhOHBlJ.dpuf
# - @: http://www.techrepublic.com/blog/smb-technologist/create-virtual-hosts-in-a-wamp-server/
# - @: http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp (maybe out of usable scope)
# afm : Agile Farm Manager
#<VirtualHost *:1983>
# DocumentRoot "D:/projects/afm/Code"
# ServerName dafm.dev
# <Directory "D:/projects/afm/Code">
# Order allow,deny
# Allow from all
# AllowOverride All
# </Directory>
#</VirtualHost>
NameVirtualHost mrs.dev:1983
# mrs : Meeting Request System
<VirtualHost *:1983>
DocumentRoot "D:/wamp/www/mrs_site/mrs"
ServerName mrs.dev
</VirtualHost>
NameVirtualHost dtk.dev:1983
# dtk : Kit Designer
<VirtualHost *:1983>
DocumentRoot "D:/wamp/www/designertoolkit/"
ServerName dtk.dev
</VirtualHost>
再次感谢@ user4311956的答案,指出我正确的方向。