繁体   English   中英

如何使用 Require 指令来限制 apache 2.4 中的文件访问

[英]How to use Require directive to limit file access in apache 2.4

对于运行 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 配置中,您必须扩展 AllowOverride 属性。 添加:FileInfo 和 AuthConfig。 或者设置“AllowOverride All”

我有同样的问题,用这个配置修复:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM