Kra*_*ime 6 .htaccess apache-2.4
我有一个网站结构设置如下,我试图组织每个访问级别,但没有指定,<Directory>
因为这需要修复结构(也就是说,如果我将其复制到不同的网站,进入子文件夹,则需要编辑所有 .htaccess 到新位置)。
我尝试过实现 Apache2.4 的 new(ish) 指令方案:
/etc/apache2/conf-enabled/security.conf
... more stuff above ...
<Directory />
AllowOverride All
Require all denied
</Directory>
... more stuff below ...
Run Code Online (Sandbox Code Playgroud)
并添加Require all allowed
到.htaccess
应用程序的根目录中,同时添加Require all denied
到.htaccess
我希望拒绝访问的文件夹中。
问题是Require all denied
似乎什么也没做。我看到过使用mod_auth_compat
或 任何一个库的参考,但它似乎只适用于旧版本的 apache (v2.3)。
我在 Debian 8 上使用 Apache 2.4。
以前,我会提供:
Order Allow, Deny
Deny from all
Run Code Online (Sandbox Code Playgroud)
然后将以下内容放入需要访问的文件夹中:
Allow from all
Run Code Online (Sandbox Code Playgroud)
..并且我需要只允许特定文件类型访问,
<FilesMatch "\.(jpg|jpeg|gif|png|bmp|svg|css|less|sass|scss|js|ttf|woff|woff2|eot)$">
Allow from all
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)
根据 apache 的文档,混合新旧声明可能会产生意想不到的结果,因此,我只使用新声明。没有杂散.htaccess
文件或*.conf
使用旧的权限声明格式加载的文件 - 所以这应该有效?
考虑到我布置的文件夹结构,以及“/etc/apache2/conf-enabled/security.conf”中加载的内容(因为这是AllowOverride的“root”声明的位置[在指定时它似乎不起作用AllowOverride All
在网站conf(000-default.conf)中相同格式的声明内,有人可以为这个问题提供一些指导或者最好是一个可行的解决方案。
请参阅带有指令示例的升级指南Require
:https ://httpd.apache.org/docs/trunk/en/upgrading.html
Deny from all
就是现在Require all denied
Allow from all
就是现在Require all granted
情节扭曲:Apache 2.4 默认情况下不授予对任何目录的访问权限,并且评估顺序已更改。
Directory /
正如您所写,在 apache 2.2 中使用+来阻止对文件系统的访问是很常见的Require all denied
。现在应该将其删除。如果它取代了子目录中的权限,将会适得其反。
请参阅有关合并身份验证限制的文档。在实践中它变得异常复杂。https://httpd.apache.org/docs/trunk/en/mod/mod_authz_core.html#authmerging
in在子目录中Require all granted
的/app
之前进行评估。看起来 apache 在满足第一个允许规则时授予访问权限,因此它是允许的。整个树是由父级指令打开的,对此您无能为力。Require all denied
/app/lib
我的建议是不要混合公共和私人内容。在实践中这是完全无法管理的。如果送达了,那就意味着送达了。
归档时间: |
|
查看次数: |
17860 次 |
最近记录: |