【问题标题】:How to use Require directive to limit file access in apache 2.4如何使用 Require 指令来限制 apache 2.4 中的文件访问
【发布时间】:2014-09-17 22:43:12
【问题描述】:

对于一个运行 apache 2.4.7 的 Ubuntu 14.04 上的网站,我有如下目录结构:

/websites/mywebsite/index.htm
/websites/mywebsite/private.htm
/websites/myqwbsite/folder/privatefile.ext
/websites/mywebsite/folder/subfolder/publicfile.ext

在网站的 Apache 配置中,我有

<Directory /websites/mywebsite/>
   AllowOverride Limit
   Require all granted
</Directory>

我想使用站点文件夹中的 .htaccess 文件,这样 private.htm 和 privatefile.ext 文件是 Require all denied,但其他所有内容都被授予。

我尝试了以下两个 .htaccess 文件:

/websites/mywebsite/.htaccess:

<FilesMatch (private.*.htm)$>
   Require all denied
</FilesMatch>

/websites/mywebsite/folder/.htaccess:

Require all denied

/websites/mywebsite/folder/subfolder/.htaccess:

Require all granted

但是,apache 为 /websites/mywebsite/.htaccess 提供 500 -“此处不允许”

如何使用兼容 apache 2.4 的配置实现我想要的(即我不想加载 mod_access_compat 并使用旧式配置)?

【问题讨论】:

标签: apache .htaccess permissions access-control


【解决方案1】:

在站点的 apache 配置中,您必须扩展 AllowOverride 属性。添加:FileInfo 和 AuthConfig。或者设置“AllowOverride All”

我有同样的问题,用这个配置解决了:

<Directory /websites/mywebsite/>
   Options +FollowSymLinks +SymLinksIfOwnerMatch
   AllowOverride FileInfo AuthConfig
</Directory>

【讨论】:

    猜你喜欢
    • 2011-03-22
    • 2019-11-03
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多