加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

身份验证 – nginx组http auth

发布时间:2020-12-13 21:31:01 所属栏目:Nginx 来源:网络整理
导读:来自apache2的唯一功能是我无法存档:让用户使用密码数据库(htpasswd)并允许访问不同的文件/文件夹/虚拟服务器. 我启用的基本http auth工作原理: location ~ ^/a/ { # should allow access for user1,user2 auth_basic "Restricted"; auth_basic_user_file

来自apache2的唯一功能是我无法存档:让用户使用密码数据库(htpasswd)并允许访问不同的文件/文件夹/虚拟服务器.

我启用的基本http auth工作原理:

location ~ ^/a/ {
    # should allow access for user1,user2
    auth_basic            "Restricted";
    auth_basic_user_file  /etc/nginx/auth/file_a;
}
location ~ ^/b/ {
    # should allow access for user2,user3
    auth_basic            "Restricted";
    auth_basic_user_file  /etc/nginx/auth/file_b;
}

如果我在file_a和user2中有user1,user2,在file_b中有user3,这可以工作,但是当我更改user2的密码时,我必须更新这两个文件(所有位置的密码应该相同).由于我将拥有> 15个具有不同访问权限和> 10个用户的不同位置,因此这不是很容易处理. (我喜欢精细的访问权限!)

使用Apache,我为每个位置定义了不同的组,并且需要正确的组.更改访问权限就像向组添加/删除用户一样简单.

是否有类似的东西或如何使用nginx轻松处理这种情况?

最佳答案
您可以使用AuthDigest模块和领域作为组来实现这一点 – 您将为一个用户提供多个条目,但您可以在一个文件中逐行排列.不完美,但比你现在的噩梦更好.

配置变化很小(请参阅第二个位置的auth_digest和user_file):

location ~ ^/a/ {
    # should allow access for user1,user2
    auth_digest            "Restricted";
    auth_digest_user_file  /etc/nginx/auth/file_a;
}
location ~ ^/b/ {
    # should allow access for user2,user3
    auth_digest            "Restricted2";
    auth_digest_user_file  /etc/nginx/auth/file_a;
}

和file_a:

user1:Restricted1:password_hash
user2:Restricted1:password_hash
user2:Restricted2:password_hash
user3:Restricted2:password_hash

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读