Apache配置基于IP的虚拟主机 Apache virtual host configuration is based on the IP

Step 1:

  检查是否开启 httpd-vhosts.conf

  apache/conf/httpd.conf文件

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

  如果没有开启,必须在httpd.conf文件中设置;如果开启,则可以在apache/conf/extra/httpd-vhosts.conf文件中设置,当然也还是可以再httpd.conf文件中进行设置,同样有效。

 

Step 2:

  httpd.conf文件 DocumentRoot一定要是要配置成虚拟主机的项目的父级目录,此处的DocumentRoot限制的级别最高,虚拟主机中设置的DocumentRoot目录级别只能等于或低于此处的DocumentRoot目录。

# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "D:\htdocs"
<Directory "D:\htdocs">

 

Step 3:

  按照Step1中的规则,添加虚拟主机配置。

<VirtualHost 127.0.0.1:80>
    DocumentRoot "D:\htdocs\project1\www"
    ServerName 127.0.0.1:80
    <Directory "D:\htdocs\project1\www">
        Options Indexes FollowSymLinks Multiviews
        AllowOverride All
        Order Allow,Deny
        Allow from all
    </Directory>
</VirtualHost>  
  
<VirtualHost 127.0.0.2:80>
    DocumentRoot "D:\htdocs\project2"
    ServerName 127.0.0.2:80
    <Directory "D:\htdocs\project2">
        Options Indexes FollowSymLinks Multiviews
        AllowOverride All
        Order Allow,Deny
        Allow from all
    </Directory>
</VirtualHost>

 

Note:

  在虚拟主机配置中一定要覆盖127.0.0.1,不然则使用httpd.conf中配置的DocumentRoot的目录,那么项目的上级目录则暴露了。

posted @ 2014-07-21 00:50  智珏  阅读(180)  评论(0编辑  收藏  举报