Apache 2.4:是否可以独立于父目录身份验证对子目录进行身份验证?

时间:2021-01-30 13:42:08

标签: apache authentication configuration config

经过广泛的谷歌搜索后,我发现了许多示例:

  1. 父目录对公众开放,但子目录和/或特定文件需要身份验证
  2. 父目录需要身份验证,但子目录和/或特定文件对公众开放

这两个目标似乎更容易实现。

但是,我似乎无法找到问题或如何执行以下操作的答案:

  1. 父目录对组和用户密码文件进行身份验证,而子目录对独立组和用户密码文件进行身份验证。

这可能吗?


例如

给定:
/wwwroot/dir
/wwwroot/dir/subdir

httpd.conf

   <Directory "/wwwroot/dir">
      Options Indexes SymLinksIfOwnerMatch
      AuthType Basic
      AuthName "Restricted Files"
      AuthBasicProvider file
      AuthUserFile /passwd/passwd.users
      AuthGroupFile /passwd/groups
      Require group some.People
   </Directory>

   <Directory "/wwwroot/dir/subdir">
      Options SymLinksIfOwnerMatch
      AuthType Basic
      AuthName "Other Restricted Files"
      AuthBasicProvider file
      AuthUserFile /passwd/passwd.other.users
      AuthGroupFile /passwd/other.groups
      Require group other.People
    </Directory>

这似乎根本不起作用。 some.People 中的用户仍然可以访问 /wwwroot/dir/subdir,而 other.People 中的用户根本不需要进行身份验证。


我什至尝试过这个(这不是我真正想要的):

httpd.conf

   <Directory "/wwwroot/dir">
      Options Indexes SymLinksIfOwnerMatch
      AuthType Basic
      AuthName "Restricted Files"
      AuthBasicProvider file
      AuthUserFile /passwd/passwd.users
      AuthGroupFile /passwd/groups
      Require group some.People other.People
   </Directory>

   <Directory "/wwwroot/dir/subdir">
      Options SymLinksIfOwnerMatch
      AuthType Basic
      AuthName "Restricted Files"
      AuthBasicProvider file
      AuthUserFile /passwd/passwd.users
      AuthGroupFile /passwd/groups
      Require group other.People
    </Directory>

这是使用共享 AuthName 和共享组和用户密码文件集设置的。即使这按我的设想工作,这也不是我真正想要的,因为这意味着 other.People 可以访问 /wwwroot/dir 父目录。但是,即使使用此设置,我也无法让 other.People/wwwroot/dir/subdir 中成功进行身份验证。


我在 apache 文档中发现了一个有点神秘的注释,即应用到同一目录的多个 <Directory> 指令按照它们在配置文件中出现的顺序进行评估,所以我也尝试交换上面的两个部分,但这似乎没有任何区别。还有一个看似矛盾的注释,即 <Directory> 指令按照最短路径到最长路径的顺序进行评估,在我看来,这表明 /wwwroot/dir 将始终在 /wwwroot/dir/subdir 之前处理。

0 个答案:

没有答案