上一篇:看不见的人是看不见自己看不见的(2018-10-23 22:11:49)
文章大纲

如何在Apache下建多个站点

2019-01-02 21:40:16


此次实践环境: Windows10 + WAMP集成环境。

建立多个站点很简单,分两步走:

第一步:在apache配置文件httpd.conf里添加监听端口。

文件位置:

E:/wamp64/www/bin/apache/apache2.4..23/conf/httpd.conf
Listen [::0]:80
Listen [::0]:81 //对应网站目录pha
Listen [::0]:82 //对应网站目录tp5


第二步:在httpd-vhosts.conf里添加每个站点的配置。

文件位置:

E:/wamp64/www/bin/apache/apache2.4..23/conf/extra/httpd-vhosts.conf

ServerName localhost
DocumentRoot E:/wamp64/www

Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local




DocumentRoot E:/wamp64/www/pha
ServerName Phalcon

Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local





DocumentRoot E:/wamp64/www/tp5
ServerName Phalcon

Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local


这里配置,80端口对应的项目根目录,81、82端口各自对应一个站点。

配置中AllowOverride是用来决定项目中.htaccess文件是否生效的。经过实践,v-hosts.conf文件中该配置的优先级高于httpd.conf的优先级。

例如v-hosts.conf中80没有设置AllowOverride,如果httpd.conf中设置如下:

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All #www目录或子目录下的.htaccess 文件有效,如果是None,则无效。

关于.htaccess文件,这里就不赘述了。


完成上面两步配置后,重启apache服务。

在浏览器里输入不同端口,就可以验证是否访问到对应网站目录去了。

http://localhost:81/

默认一般访问index.php文件,所以你可以在pha和tp5各自建个index.php文件来验证喽。




上一篇:看不见的人是看不见自己看不见的(2018-10-23 22:11:49)
我要评论
评论列表