首页 > 其他 > 详细

Apache配置基于端口号的虚拟主机 Apache virtual host configuration is based on the port

时间:2014-07-22 00:39:06      阅读:315      评论:0      收藏:0      [点我收藏+]

有可能只有一个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:

  httpd.conf文件中添加多端口监听。

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80
Listen 81
Listen 82

 

Step 4:

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

<VirtualHost *: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 *:81> DocumentRoot "D:\htdocs\project2" ServerName 127.0.0.1:81 <Directory "D:\htdocs\project2"> Options Indexes FollowSymLinks Multiviews AllowOverride All Order Allow,Deny Allow from all </Directory> </VirtualHost>

 

Note:

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

Apache配置基于端口号的虚拟主机 Apache virtual host configuration is based on the port,布布扣,bubuko.com

Apache配置基于端口号的虚拟主机 Apache virtual host configuration is based on the port

原文:http://www.cnblogs.com/hlt1988321/p/3857596.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!