Apache2中是否可以有两个密码文件?

问题描述 投票:5回答:2

我在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中,而对于svn仅包含1个,在trac位置包含两个。

apache apache2 basic-authentication
2个回答
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组的成员访问此资源。

如果您really要使用多个密码文件,请参阅mod_authn_alias的文档,其中有一个示例可以做到这一点。


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

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

© www.soinside.com 2019 - 2024. All rights reserved.