1.在\wamp\bin\apache\apache2.4.9\conf\extra中找到httpd-vhosts文件,用写字板打开,在后边可以看到
<VirtualHost *:80>
【ServerAdmin ...】 ---设置管理员邮箱地址
【DocumentRoot ...】 ---网站代码存放位置目录
【ServerName ...】 ---主机名
ServerAlias www.dummy-host.example.com
【ErrorLog ...】 ---错误日志
【CustomLog ...】 ---日常日志
</VirtualHost>
只需更改DocumentRoot与ServerName,其它信息暂不用删掉
更改后----
<VirtualHost *:80>
DocumentRoot "h:/web"
ServerName test.com
</VirtualHost>
2.打开\wamp\bin\apache\apache2.4.9\conf中的httpd.conf,按Ctrl+F搜索httpd-vhosts,去掉#Include conf/extra/httpd-vhosts.conf前的#使得apache服务器包含httpd-vhosts.conf
AllowOverride all
Require all granted
4.重启wamp所有服务
5、打开C盘->windows->System 32->drivers->etc->hosts文件,在最下方添加如下代码(添加几个站点,添加几个即可,使系统优先访问我们新增的站点域名。)
127.0.0.1 test.com
<VirtualHost *:80>
【ServerAdmin ...】 ---设置管理员邮箱地址
【DocumentRoot ...】 ---网站代码存放位置目录
【ServerName ...】 ---主机名
ServerAlias www.dummy-host.example.com
【ErrorLog ...】 ---错误日志
【CustomLog ...】 ---日常日志
</VirtualHost>
只需更改DocumentRoot与ServerName,其它信息暂不用删掉
更改后----
<VirtualHost *:80>
DocumentRoot "h:/web"
ServerName test.com
</VirtualHost>
2.打开\wamp\bin\apache\apache2.4.9\conf中的httpd.conf,按Ctrl+F搜索httpd-vhosts,去掉#Include conf/extra/httpd-vhosts.conf前的#使得apache服务器包含httpd-vhosts.conf
3.这时候进之前设定的test.com会提示 Forbidden You don't have permission to access / on this server.
解决办法 (Apache2.2以后的版本)在httpd.conf文件中搜索<Directory 找到有# onlineoffline tag - don't remove的那一段,将它改为
# onlineoffline tag - don't removeAllowOverride all
Require all granted
4.重启wamp所有服务
5、打开C盘->windows->System 32->drivers->etc->hosts文件,在最下方添加如下代码(添加几个站点,添加几个即可,使系统优先访问我们新增的站点域名。)
127.0.0.1 test.com