8.配置段合并
(1)<Directory>和.htaccess同时处理
(2)<DirectoryMatch>和<Directory ~>同时处理
(3)<Files>和<FilesMatch>同时处理
(4)<Location>和<LocationMatch>同时处理
说明:
(1)当请求是由mod_proxy处理时,<Proxy>容器将会在处理顺序中取代<Directory>容器的位置
(2)<Directory>容器使用短目录优先的规则进行应用(即按字典顺序由短到长依次处理),其他配置段按它们在配置文件中出现的顺序依次被处理
(3)<VirtualHost>容器中的配置段在外部对应的段处理完毕后再处理,这样就允许虚拟主机覆盖主服务器的设置
(4)用Include指令包含进来的配置被视为按原样插入到Include指令所在的位置
(5)配置处理自动继承到下一级子目录
(6)处理顺序中位于后面的段将覆盖前面的段的相应配置项
举例:
目录结构如下:
-domain1
test.php
index2.php
.htaccess
-test
test.php
index2.php
-test_sub
test.php
index2.php
-test_sub_sub
test.php
index2.php
-test2
test.php
index2.php
.htaccess
-test3
test.php
index2.php
httpd.conf部分配置段信息如下:
<VirtualHost 192.168.1.102:80>
ServerName
www.domain1.dawn ServerAlias domain1.dawn *.domain1.dawn
DocumentRoot /www/domain1
<Location /test/test_sub>
# H 允许对/test/test_sub网络空间的访问
Order deny,allow
Deny from all
Allow from all
</Location>
<Directory D:/AppServ/www/domain1/test>
# B 允许Indexes指令覆盖
Options None
AllowOverride Options=Indexes
Order deny,allow
Deny from all
Allow from all
<Files test.php>
# F 允许访问/www/domain1/test其子目录中的test.php文件
Order deny,allow
Deny from all
Allow from all
</Files>
</Directory>
<Directory D:/AppServ/www/domain1>
# A 允许Order、Indexes指令覆盖
Options None
AllowOverride Limit Options=Indexes
Order deny,allow
Deny from all
Allow from all
<Files test.php>
# E 拒绝访问/www/domain1目录及其子目录中的test.php文件
Order deny,allow
Deny from all
</Files>
</Directory>
<Files test.php>
# D 允许访问/www/domain1目录及其子目录中的test.php文件
Order deny,allow
Deny from all
Allow from all
</Files>
<Location /test>
# I 拒绝对/test网络空间的访问
Order deny,allow
Deny from all
</Location>
# J 允许对/test/test_sub/test_sub_sub网络空间的访问
Include "conf/test.conf"
</VirtualHost>
<Files test.php>
# C 拒绝对test.php文件的访问
Order deny,allow
Deny from all
</Files>
<Location /test/test_sub>
# G 拒绝对/test/test_sub网络空间的访问
Order deny,allow
Deny from all
</Location>
conf/test.conf配置段信息如下:
<Location /test/test_sub/test_sub_sub>
Order deny,allow
Deny from all
Allow from all
</Location>
/www/domain1/下.htaccess配置段信息如下:
# 开启目录列表功能
Options Indexes
Order deny,allow
Deny from all
Allow from all
/www/domain1/test2/下.htaccess配置段信息如下:
# 关闭目录列表功能
Options None
Order deny,allow
Deny from all
Allow from all
配置段的合并处理顺序为:A->B->C->D->E->F->G->H->I->J
合并处理结果:
(1)/及/test3网络空间具有目录列表功能
(2)允许使用HTTP协议访问以下文件:
/www/domain1/index2.php
/www/domain1/test/test_sub/test_sub_sub/index2.php
/www/domain1/test/test_sub/test_sub_sub/test.php
/www/domain1/test2/index2.php
/www/domain1/test3/index2.php