在Apache2中可以有两个密码文件吗?

时间:2012-05-10 19:07:27

标签: apache apache2 basic-authentication http-basic-authentication

我可以在apache2 / sites-enabled / 000-default配置文件中有两个AuthUserFile指令吗?

    <Location /repo/trac>
      AuthType Basic
      AuthName "Trac"
      AuthUserFile /etc/apache2/passfile1
      AuthUserFile /etc/apache2/passfile2
      Require valid-user
    </Location>

我想要两种类型用户的用户名/密码。

  • DEV - 可以访问SVN和Trac
  • NOM - 只能访问Trac

我有两个选择:为Trac和Svn保留单独的密码文件并单独包含它们,或者在1中放入2个密码文件我将DEV放在其他NOM中,仅包含1个用于svn,并在trac位置包含两个。

2 个答案:

答案 0 :(得分:8)

您应该将所有内容移动到一个密码文件中,然后使用组来控制对特定资源的访问。您可以使用以下内容创建/etc/apache2/groups

DEV: bob alice
NOM: norm fred bart

然后修改您的配置,使其如下所示:

<Location /repo/trac>
  AuthType Basic
  AuthName "Trac"
  AuthUserFile /etc/apache2/passfile
  AuthGroupFile /etc/apache2/groups
  Require group DEV NOM
</Location>

这将允许DEVNOM组的成员访问此资源。

如果确实想要使用多个密码文件,请参阅mod_authn_alias的文档,其中有一个示例正是如此。

答案 1 :(得分:0)

在文档中,您实际上可以拥有多个密码文件。诀窍是使用AuthnProviderAlias

https://httpd.apache.org/docs/2.4/mod/mod_authn_core.html

<AuthnProviderAlias file file1>
    AuthUserFile "/www/conf/passwords1"
</AuthnProviderAlias>

<AuthnProviderAlias file file2>   
    AuthUserFile "/www/conf/passwords2"
</AuthnProviderAlias>

<Directory "/var/web/pages/secure">
    AuthBasicProvider file1 file2
    AuthType Basic
    AuthName "Protected Area"
    Require valid-user
</Directory>

https://httpd.apache.org/docs/2.4/en/mod/mod_auth_basic.html#authbasicprovider

  

将按顺序查询提供者,直到提供者找到与所请求用户名匹配的内容为止,此时唯一的提供者将尝试检查密码。验证密码失败不会导致控制权传递给后续提供者。

相关问题