开发者

Wamp Server: Multiple Virtual Hosts are not working on Windows

开发者 https://www.devze.com 2022-12-24 03:56 出处:网络
I have two virtual hosts on windows(for example: test1.dev and test2.dev). But it always load c开发者_开发知识库ontent of test1.dev for both virtual hosts.

I have two virtual hosts on windows(for example: test1.dev and test2.dev). But it always load c开发者_开发知识库ontent 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 ?


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


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>


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>


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.


I changed

NameVirtualHost *:80

to

NameVirtualHost 127.0.0.1:80

and it works for me


Don't forget to check for lines like "Listen [::0]:80" in httpd.conf and add your ports there too, if NameVirtualHost doesn't work.


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号