1 编辑httpd.conf,查找Include conf/extra/httpd-vhosts.conf,把前面注释符号“#”删掉。
2 编辑httpd-vhosts.conf,我把WAMPServer安装在D:/wamp,所以我这里的路径是D:\wamp\Apache2\conf\extra。
把里面的内容清空掉,换成下面的内容:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.host1.com
ServerAlias www.host1.com
DocumentRoot "D:/wamp/www/host1"
</VirtualHost>
<VirtualHost *:80>
ServerName www.host2.com
ServerAlias www.host2.com
DocumentRoot "D:/wamp/www/host2"
</VirtualHost>
3 编辑httpd.conf,找到DocumentRoot "d:/wamp/www/"这项,这是默认根目录路径,但是要更改的不是这个,一直往下找,找到<Directory "d:/wamp/www">,然后在该</Directoory>后加上如下内容:
<Directory "d:/wamp/www/host1">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
<Directory "d:/wamp/www/host2">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
4 修改C:/WINDOWS/system32/drivers/etc/hosts这个文件,用记事本打开,加上如下内容:
127.0.0.1 www.host1.com
127.0.0.1 www.host2.com
好了,然后重启apache,在浏览器里面输入www.host1.com,看看访问到的内容是不是host1这个目录呢。
丸子:
<VirtualHost *:80>
DocumentRoot D:/wamp/www/test
ServerName www.test.com
</VirtualHost>