基于IP的虚拟主机使用连接的IP地址来决定相应的虚拟主机。这样,你就需要为每个虚拟主机分配一个独立的IP地址。
而基于域名的虚拟主机是根据客户端提交的HTTP头中标识主机名的部分决定的。使用这种技术,很多虚拟主机可以共享同一个IP地址
- 基于IP的虚拟主机,通过端口区分:
1、httpd.conf启动虚拟主机的配置
2、配置httpd-vhosts添加虚拟主机监听端口为80
<VirtualHost 127.0.0.1:80>
DocumentRoot "" #第一个网站的根目录
DirectoryIndex index.html index.php
<Directory>
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost >
添加另一个虚拟主机,假设监听81端口
<VirtualHost 127.0.0.1:81>
DocumentRoot "" #第二个网站的根目录
DirectoryIndex index.html index.php
<Directory>
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost >
3、在httpd-vhosts(建议)注销默认的DocumentRoot
4、在htttpd.conf让apache监听其他端口如81
5、在hosts文件添加多对ip和域名的对应关系
C:/window/system32/drivers/etc/hosts
6、重启apache
- 基于域名的虚拟主机,通过ServerName区分域名
1、httpd.conf启动虚拟主机的配置
2、配置httpd-vhosts
<VirtualHost *:80>
DocumentRoot "" #网站的根目录
ServerName www.xxxxxx.com #修改此处
DirectoryIndex index.html index.php
<Directory>
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost >
3、在hosts文件添加多对ip和域名的对应关系
4、重启apache
详情可以查看我的另外一篇:http://www.cnblogs.com/mackxu/archive/2012/04/10/2439917.html