打开Apache的配置文件httpd.conf
在Listen 80
下面添加多个监听端口如
Listen 8011
Listen 8088
这样就增加了8011和8088端口的监听
然后在最后的位置设置虚拟主机目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
NameVirtualHost
*: 80 <VirtualHost
*: 80 > ServerName
localhost DocumentRoot
"D:/wwwroot/web1" </VirtualHost> NameVirtualHost
*: 8011 <VirtualHost
*: 8011 > ServerName
localhost: 8011 DocumentRoot
"D:/wwwroot/web2" </VirtualHost> NameVirtualHost
*: 8088 <VirtualHost
*: 8088 > ServerName
localhost: 8088 DocumentRoot
"D:/wwwroot/web3" </VirtualHost> |
像这样,重启Apache服务,即可以用
localhost
localhost:8011
localhost:8088
访问你不同的网站了
还可以用同一个端口不同的域名或者IP地址
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
NameVirtualHost
*: 80 <VirtualHost
*: 80 > ServerName
127.0 . 0.1 DocumentRoot
"D:/wwwroot/web1" </VirtualHost> NameVirtualHost
*: 80 <VirtualHost
*: 80 > ServerName
127.0 . 0.2 : 80 DocumentRoot
"D:/wwwroot/web2" </VirtualHost> NameVirtualHost
*: 80 <VirtualHost
*: 80 > ServerName
127.0 . 0.3 : 80 DocumentRoot
"D:/wwwroot/web3" </VirtualHost> |
可以用过127.0.0.1,127.0.0.2,127.0.0.3访问这三个站点了。