Wamp Server: Multiple Virtual Hosts are not working on Windows

安稳与你 提交于 2019-12-29 04:50:26

问题


I have two virtual hosts on windows(for example: test1.dev and test2.dev). But it always load content of test1.dev for both virtual hosts.

Following are my files:

hosts:

127.0.0.1    localhost
127.0.0.1    test1.dev
127.0.0.1    test2.dev

httpd.conf:

<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

Include "c:/wamp/alias/*"

<VirtualHost 127.0.0.1>
    ServerName test1.dev
    DocumentRoot "C:\wamp\www\test1\public"
</VirtualHost>

<VirtualHost 127.0.0.1>
    ServerName test2.dev
    DocumentRoot "C:\wamp\www\test2\public"
</VirtualHost>

Can someone recognize the problem ?


回答1:


I'm guessing you're missing the NameVirtualHost 127.0.0.1:80 line somewhere :)




回答2:


I did some thing like this 1- for the local host its :

NameVirtualHost localhost:80
<VirtualHost localhost:80>
ServerName localhost
ServerAlias localhost
DocumentRoot D:/wamp/www
ErrorLog "D:/wamp/www/error.log"
CustomLog D:/wamp/www/access.log common
<Directory "D:/wamp/www">
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride All
    <IfModule mod_access.c>
    Order allow,deny
    Allow from all
    </IfModule>
</Directory>
</VirtualHost>

2 - and for any other local domain

NameVirtualHost zf.local:80
<VirtualHost zf.local:80>
ServerName zf.local
ServerAlias zf.local 
DocumentRoot D:/Workspace/Zend/documentation
ErrorLog "D:/Workspace/Zend/documentation/error.log"
CustomLog D:/Workspace/Zend/documentation/access.log common
<Directory "D:/Workspace/Zend/documentation">
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride All
    <IfModule mod_access.c>
    Order allow,deny
    Allow from all
    </IfModule>
</Directory>
</VirtualHost>



回答3:


You don't have to write virtual host info into httpd.conf. Just uncomment line on which you load conf/extra/httpd-vhosts.conf, then go to this file and put your info there. Should work.

Example of my httpd-vhosts.conf:

NameVirtualHost *:80

<VirtualHost 127.0.0.1>
    DocumentRoot "C:/wamp/www"
    ServerName dev
</VirtualHost>



回答4:


You need to include something similar to following line

NameVirtualHost *

Also, it seems you are using https connection to the server which doesn't play well with virtual hosts because of the SSL protocol limitation. The Host header in the http request is encrypted and by the time apache decrypts it, it has already passed on the request to one of the virtual host.




回答5:


I changed

NameVirtualHost *:80

to

NameVirtualHost 127.0.0.1:80

and it works for me




回答6:


Hey guys I've written a very straight forward tutorial which includes the whole process. Let me know if you run into any problems in a comment.

http://www.kintek.com.au/web-design-blog/configuring-multiple-domains-within-wamp-for-local-development/



来源:https://stackoverflow.com/questions/2530418/wamp-server-multiple-virtual-hosts-are-not-working-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!