Apache如何合并多个匹配的位置部分

我正在研究一些基本的apacheconfiguration,但是我不明白apache如何合并不同的<Location>部分,当其中有几个匹配传入的请求URL时。 在“如何合并部分”章节中的apache文档有点混淆,当涉及到相同types的几个匹配部分的顺序/优先级。

例如,想象下面的apacheconfiguration(忽略实际内容是否有意义,我只对每个规则/部分的应用顺序感兴趣):

 <Location / > ProxyPass http://backend.com/ Order allow,deny Satisfy any </Location> <Location /sub/foo> Order allow,deny </Location> <Location /sub > Order deny,allow Require valid-user Satisfy all </Location> <Location /doesnt/match > ProxyPass ! </Location> 

现在,如果一个客户端向/sub/foobar发出一个请求,这是最终的configuration,将被应用到这个请求?

应用configuration是否相当于:

 # All the directives contained in all the matchin Locations in declaration order ProxyPass http://backend.com/ Order allow,deny Satisfy any Order allow,deny Order deny,allow Require valid-user Satisfy all 

或者可能

 # same as above, but with longest matching path last ProxyPass http://backend.com/ Order allow,deny Satisfy any Order deny,allow Require valid-user Satisfy all Order allow,deny 

或者完全不同的东西。

感谢您的帮助,我真的很困惑。

    根据文档 ,合并顺序在下表中给出。 我的testing表明,它积累了指令,最后一个获胜。 (* ProxyPass的处理方式不同,请参见注释)

    1. <Directory>(正则expression式除外)和.htaccess同时完成(使用.htaccess,如果允许,覆盖<Directory>)
    2. <DirectoryMatch>(和<Directory〜>)
    3. 同时完成<Files>和<FilesMatch>
    4. <Location>和<LocationMatch>同时完成

    除了<Directory>之外,每个组按照出现在configuration文件中的顺序进行处理。

    因此, Location将覆盖DirectoryMatch Files ,其path与最低优先级的Directory匹配。 因此,在上面的例子中,对/sub/foobar的请求将按顺序匹配前3个位置,因此最后一个匹配冲突指令会胜出。

    所以从你上面的例子来看

     <Location / > ProxyPass http://backend.com/ Order allow,deny Satisfy any </Location> <Location /sub/foo> Order allow,deny </Location> <Location /sub > Order deny,allow Require valid-user Satisfy all </Location> <Location /doesnt/match > ProxyPass ! </Location> 

    去….

      ProxyPass http://backend.com/ Order allow,deny Satisfy any Order allow,deny Order deny,allow Require valid-user Satisfy all ProxyPass ! <--- not matches 

    去哪;

      ProxyPass http://backend.com/ Order deny,allow Require valid-user Satisfy all 

    (你是对的,从文档中不清楚一些边界情况是如何解决的,其可能allow from * type指令的任何allow from *将被连接到相关的Order allow,deny ,但是我没有testing它。如果您匹配Satisfy Any情况会发生什么,但您之前收集了Allow from * …)

    有关ProxyPass的有趣说明

    只是为了烦人, ProxyPass似乎在另一个方向工作…. ;-)它基本上击中第一场比赛,然后停下来使用它!

     Ordering ProxyPass Directives The configured ProxyPass and ProxyPassMatch rules are checked in the order of configuration. The first rule that matches wins. So usually you should sort conflicting ProxyPass rules starting with the longest URLs first. Otherwise later rules for longer URLS will be hidden by any earlier rule which uses a leading substring of the URL. Note that there is some relation with worker sharing. For the same reasons exclusions must come before the general ProxyPass directives.