apache配置多ip虚拟有2种方法

第一种-通过设置不同的端口来配置

1创建一个目录,作为接口

2设置apche虚拟主机(不用配置虚拟目录映射)

  httpd.conf开启虚拟主机配置,接着到httpd-vhosts.conf里面设置

 

 
  
  1. <VirtualHost 127.0.0.1:80>    //这里改变端口 
  2.    DocumentRoot "D:/myblog"  //这个就是第一步创建的接口 
  3.    DirectoryIndex index.html index.htm index.php 
  4.    <Directory /> 
  5.    Options FollowSymLinks 
  6.    Allowoverride None 
  7.    order Allow,deny 
  8.    Allow from all 
  9.    </Directory> 
  10. </VirtualHost> 
  11.  
  12. <VirtualHost 127.0.0.1:81> 
  13.    DocumentRoot "D:/baidu" 
  14.    DirectoryIndex index.html index.htm index.php 
  15.    <Directory /> 
  16.    Options FollowSymLinks 
  17.    Allowoverride None 
  18.    order Allow,deny 
  19.    Allow from all 
  20.    </Directory> 
  21. </VirtualHost> 

3-到httpd.conf文件里面修改监听端口

 
  
  1. Listen 80 
  2. Listen 81 

4-到host文件里面修改映射.登录网站时候记得加端口号。

第二种方法:通过ServerName配置

  1创建一个目录,作为接口

2设置apche虚拟主机(不用配置虚拟目录映射)

  httpd.conf开启虚拟主机配置,接着到httpd-vhosts.conf里面设置

 

 
  
  1. <VirtualHost *:80>  //记得ip必须为*否则不行的 
  2.    DocumentRoot "D:/myblog"  //目录 
  3.    ServerName www.lengai.com  //域名 
  4.    DirectoryIndex index.html index.htm index.php 
  5.    <Directory /> 
  6.    Options FollowSymLinks 
  7.    Allowoverride None 
  8.    order Allow,deny 
  9.    Allow from all 
  10.    </Directory> 
  11. </VirtualHost> 
  12.  
  13. <VirtualHost *:80> 
  14.    DocumentRoot "D:/baidu" 
  15.     ServerName www.beijing.com 
  16.    DirectoryIndex index.html index.htm index.php 
  17.    <Directory /> 
  18.    Options FollowSymLinks 
  19.    Allowoverride None 
  20.    order Allow,deny 
  21.    Allow from all 
  22.    </Directory> 
  23. </VirtualHost> 

  3重启apache。就可以了,当然要配置hosts