一、配置httpd.conf
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf //取消这一行的#
二、配置httpd-vhosts.conf文件
1.多IP模式
<VirtualHost *:80>
DocumentRoot "E:/www/htdocs" //虚拟主机文件夹
ServerName 127.0.0.1 //访问IP地址
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "E:/www/htdocsA"
ServerName 127.0.0.2
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "E:/www/htdocsB"
ServerName 127.0.0.3
</VirtualHost>
2.多站点设置
<VirtualHost *:80>
DocumentRoot "E:/www/htdocs" //虚拟主机文件夹
ServerName www.a.com //访问的域名
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "E:/www/htdocsA"
ServerName www.b.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "E:/www/htdocsB"
ServerName www.c.com
</VirtualHost>
3.多端口
<VirtualHost *:8080>
DocumentRoot "E:/www/htdocs" //虚拟主机文件夹
ServerName 127.0.0.1 //访问的IP及端口
</VirtualHost>
<VirtualHost *:8081>
DocumentRoot "E:/www/htdocsA"
ServerName 127.0.0.1
</VirtualHost>
<VirtualHost *:8082>
DocumentRoot "E:/www/htdocsB"
ServerName 127.0.0.1
</VirtualHost>
三、修改windows系统下的C:WindowsSystem32driversetchosts文件(需要管理员身份,不然无法修改)
# IP Hosts
127.0.0.1 localhost
127.0.0.1 bookstore
127.0.0.1 diaryfood
Hosts参数需要跟ServerName参数名是一样的,这样就可以通过在浏览器的地址栏里输入 bookstore:8080 访问相应的虚拟网站了