一、通过端口来区分不同的虚拟主机 (站点)
1)指定项目所在位置,例:d:/test1 d:/test2
2)php中配置conf下面的httpd.conf文件,启用extra目录下的httpd-vhosts.conf
Include conf/extra
DocumentRoot "d:/test1"
DirectoryIndex test.html index.html index.htm index.php <-- test.html为自己想要的首页-->
<Directory/>
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost 127.0.0.1:81>
DocumentRoot "d:/test2"
DirectoryIndex test.html index.html index.htm index.php <-- test.html为自己想要的首页-->
<Directory/>
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
4)在c:/windows/system32/driver/etc/hosts文件中添加IP和域名的对应关系,例:
127.0.0.1:80 www.test1.com
127.0.0.1:81 www.test2.com
5)在httpd.conf文件中让apache监听81端口
Listen81
6)测试
www.test1.com www.test2.com:81
二、通过ServerName端来区分不同的域名
1)指定项目所在位置,例:d:/test1 d:/test2
2)在httpd-vhosts.conf文件中添加配置
<VirtualHost *:80><-- Host改为*号-->
DocumentRoot "d:/test1"
ServerName www.test1.com
DirectoryIndex test.html index.html index.htm index.php <-- test.html为自己想要的首页-->
<Directory/>
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80><-- Host改为*号-->
DocumentRoot "d:/test2"
ServerName www.test2.com
DirectoryIndex test.html index.html index.htm index.php <-- test.html为自己想要的首页-->
<Directory/>
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
127.0.0.1 www.test1.com
127.0.0.1 www.test2.com
4)测试
www.test1.com