1. apache\conf\httpd.conf 中vhosts包含#去掉,如下:
# Virtual hosts
Include "conf/extra/httpd-vhosts.conf"
2.修改C:\Windows\System32\drivers\etc\hosts,添加虚拟地址与ip映射
192.168.1.71 myself.newdev.zhiwo.com
192.168.1.71 www.test.com
3.修改 apache\conf\extra\httpd-vhosts.conf 如下:
NameVirtualHost *:80 --前面的两个##号去掉
#myself.newdev.zhiwo.com对应的配置
<VirtualHost *:80>
ServerAdmin postmaster@dummy-host.localhost
DocumentRoot "D:/xampplite/htdocs/dapperPHP/webroot/"
ServerName 192.168.1.71:80
ServerAlias myself.newdev.zhiwo.com
ErrorLog "logs/dummy-host.localhost-error.log"
CustomLog "logs/dummy-host.localhost-access.log" combined
Alias /static/ "D:/xampplite/htdocs/dapperPHP/View/"
<Directory "D:/xampplite/htdocs/dapperPHP/webroot/">
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
#www.test.com对应的配置
<VirtualHost *:80>
ServerAdmin postmaster@dummy-host2.localhost
DocumentRoot "D:/xampplite/htdocs/test/"
ServerName 192.168.1.71:80
ServerAlias www.test.com
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" combined
<Directory "D:/xampplite/htdocs/test/">
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
4.重启apache和浏览器,分别输入myself.newdev.zhiwo.com,www.test.com就会打开其相对应的网页