Apache - 如何拒绝目录但允许该目录中的一个文件

Mao*_*any 23 apache security webserver

我尝试配置我的Apache .conf文件以拒绝某个类别的列表,但我想允许此类别中的特定文件.看起来目录规则比"文件"规则"更强",所以当使用两者时 - 我无法访问该特定文件.

这是我尝试的:

<Directory /var/www/denied_directory>
     order deny,allow
     Deny From All
</Directory>

<Files safefile.php>
    Order Allow,Deny
    Allow from All
</Files>
Run Code Online (Sandbox Code Playgroud)

ako*_*ond 20

如果配置正确,它可以正常工作:

   <Directory /var/www/denied_directory>
        Order allow,deny
        <Files test.php>
           Order deny,allow
        </Files>
   </Directory>
Run Code Online (Sandbox Code Playgroud)

  • 同样在这里.403禁止.为什么这是20 +票? (2认同)

Dav*_*fer 9

在Apache 2.4中,对环境变量进行额外测试以获得良好的衡量标准:

另请参阅:需要指令

<Directory "/wikis/foswiki">

    Require all denied

    # Allow access to toplevel files ending in .html (in particular index.html) only 
    # (comment out if you don't care for this)

    <Files ~ "\.html$">

       <RequireAll>
          Require all granted
          Require not env blockAccess
       </RequireAll>

    </Files>

</Directory>
Run Code Online (Sandbox Code Playgroud)