繁体   English   中英

Apache 2.4 - 如何拒绝对 DocumentRoot 的访问,但允许对 DirectoryIndex 文件的“尾部斜杠”访问

[英]Apache 2.4 - How to deny access to DocumentRoot but allow 'trailing slash' access to DirectoryIndex file

在我的 Apache 2.4 VirtualHost 配置中,我想 - 默认情况下 - 拒绝访问我没有明确启用的DocumentRoot中的所有内容。 为此,我写道:

DocumentRoot /var/www
<Directory "/var/www">
  Require all denied 
  <Files "index.html">
    Require all granted
  </Files>
</Directory>

这允许直接访问http://myserver.example/index.html ,但会导致403响应间接访问http://myserver.example/

我该如何纠正这种行为?

遵循我“没有明确允许/ ”的提示,导致它被禁止让我走上解决这个问题的正确轨道。 添加专门处理尾部斜杠的LocationMatch指令会导致所需的行为:

DocumentRoot /var/www
<Directory "/var/www/">
  Require all denied
  <Files "index.html">
    Require all granted
  </Files>
</Directory>

# Regex anchored at string beginning and end
# -> only matches "/"
<LocationMatch "^/$">
  Require all granted
</LocationMatch>

请注意,添加<Files "/">指令不起作用,可能是因为访问的资源不是真正的文件。 <Location />也不是正确的,因为它将应用于整个 VirtualHost。

暂无
暂无

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

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