1、修改host文件,一般在 C:/WINDOWS/system32/drivers/etc 目录下,在文件最后添加:

  127.0.0.1 www.test1.demo

  127.0.0.1 www.test2.demo

  在Wamp下的WWW文件夹下创建新文件夹:“test1” 、“test2”,对应两个域名。

2、打开apache目录下的(D:\wamp\bin\apache\apache2.4.9\conf),找到文件:
  httpd.conf

  找到行:
  #Virtualhosts
  #Includeconf/extra/httpd-vhosts.conf


  去掉Includeconf前面的#,此时无法打开localhost,需要在httpd-vhosts.conf中继续配置。

 

3、打开(D:\wamp\bin\apache\apache2.4.9\conf\extra)下的文件:

  httpd-vhosts.conf

  将默认段落修改为:

 

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "d:/wamp/www/test1"
ServerName www.test1.demo
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
<Directory "d:/wamp/www/test1">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "d:/wamp/www/test2"
ServerName www.test2.demo
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
<Directory "d:/wamp/www/test2">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "d:/wamp/www"
ServerName localhost
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
<Directory "d:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

 

红色背景部分为需要修改的内容。添加第三段的目的是:将localhost指向默认的www根目录(也可以不做此操作,则输入localhost时打开www下的第一个站点)。

 

关于WAMP多站点配置,我曾经在网上搜了好久,但并未发现合适的方案能解决此问题,这过程中还多次因为httpd.conf文件配置错误造成apache无法启动。希望本文能帮你节省时间、帮助到有需要的朋友。转载请注明出处。

posted on 2016-01-05 22:40  fuhao31  阅读(243)  评论(0编辑  收藏  举报