我们正在使用Apache-2.4提供的新身份验证和授权框架,并且需要关闭整个站点(位置/)以进行未经授权的访问,除了一个子目录(Location / foo),其中可以获得授权cookie。看来,AuthMerging是使用的指令,但事情不起作用:
<Location />
AuthType form
AuthFormProvider foo
Session On
SessionCookieName ti2f
Include conf/sessionpw.conf
AuthName TI
<RequireAll>
Require foo ipaddress
Require foo expiration
</RequireAll>
ErrorDocument 401 /foo/
</Location>
<Location /foo>
AuthMerging Or
Require all granted
DirectoryIndex index.php
</Location>
不幸的是,访问/ foo仍然被阻止 - 401 Unauthorized。随着LogLevel的启动,我可以看到mod_authz_core记录的以下消息:
authorization result of Require all granted: granted
authorization result of <RequireAny>: granted
authorization result of AuthMerging Any: granted
authorization result of Require all granted: granted
authorization result of <RequireAny>: granted
authorization result of AuthMerging Any: granted
authorization result of Require foo ipaddress: denied (no authenticated user yet)
authorization result of Require foo expiration: denied (no authenticated user yet)
authorization result of <RequireAll>: denied (no authenticated user yet)
authorization result of <RequireAny>: denied (no authenticated user yet)
对于sublocation / foo,将AuthMerging设置为“Or”,为什么Apache在“需要所有授予”授权后完全检查父位置的require-directives?
答案 0 :(得分:0)
改为使用LocationMatch:
<LocationMatch "!^/foo">
# lock down everything EXCEPT /foo
</LocationMatch>
答案 1 :(得分:0)
经过一些调试后,我能够解决问题。关于Apache的授权核心(并且据报道,在Apache-2.2中更糟糕)的奇怪之处在于规则(如果有的话)可以在每次命中多次应用。例如,在上面的情况中,对于相同的请求,这发生了三次 - 对于“/ foo /”
当前Apache的行为是错误的还是仅仅是奇怪的仍然存在争议,但我的解决方案是描述我的子位置:
<LocationMatch ^(/php-fpm)?/foo/>
Require all granted
DirectoryIndex index.php
</LocationMatch>
在这种情况下甚至不需要AuthMerging。或者我也可以添加另一个位置 - / php-fpm /。无论哪种方式,一旦理解了问题,就可以获得解决方案......