nginx 的http_auth_basic_module登录校验模块

Directives

Syntax:auth_basic string | off;
Default:
auth_basic off;
Context:httpserverlocationlimit_except

Enables validation of user name and password using the “HTTP Basic Authentication” protocol. The specified parameter is used as a realm. Parameter value can contain variables (1.3.10, 1.2.7). The special value off allows cancelling the effect of the auth_basic directive inherited from the previous configuration level.

 

Syntax:auth_basic_user_file file;
Default:
Context:httpserverlocationlimit_except

Specifies a file that keeps user names and passwords, in the following format:

# comment
name1:password1
name2:password2:comment
name3:password3

The file name can contain variables.

The following password types are supported: 密码支持的加密方式

  • encrypted with the crypt() function; can be generated using the “htpasswd” utility from the Apache HTTP Server distribution or the “openssl passwd” command;

  htppasswd安装查询:rpm -qf /usr/bin/htpasswd 

   yum安装 : yum install httpd-tools

创建用户名及密码文件:

    eg: htpasswd -c ./path/filename  keyname  回车后输入密码就可以

         

  • hashed with the Apache variant of the MD5-based password algorithm (apr1); can be generated with the same tools;
  • specified by the “{scheme}data” syntax (1.0.3+) as described in RFC 2307; currently implemented schemes include PLAIN (an example one, should not be used), SHA (1.3.13) (plain SHA-1 hashing, should not be used) and SSHA (salted SHA-1 hashing, used by some software packages, notably OpenLDAP and Dovecot).
    Support for  SHA scheme was added only to aid in migration from other web servers. It should not be used for new passwords, since unsalted SHA-1 hashing that it employs is vulnerable to rainbow table attacks.

nginx -t -c

nginx -s reload 

 

局限性:

需要提前设置密码文件 、管理麻烦效率低下

 

解决方案:

1. 通过lua文件实现

2. nginx和LDAP打通,利用nginx_auth_ladap实现

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Nginx中添加http_auth_request_module模块,你可以按照以下步骤操作: 1. 确认你的Nginx版本是否支持http_auth_request_module模块。你可以使用以下命令来检查: ``` nginx -V ``` 在输出结果中查找是否包含 "--with-http_auth_request_module" 字样,如果有,说明该模块已经被支持。 2. 如果你的Nginx版本不支持该模块,你需要重新编译Nginx并启用该模块。首先,下载Nginx的源代码: ``` wget http://nginx.org/download/nginx-x.x.x.tar.gz ``` (将 "x.x.x" 替换为你想要下载的版本号) 3. 解压源代码包: ``` tar -zxvf nginx-x.x.x.tar.gz ``` 4. 进入解压后的目录: ``` cd nginx-x.x.x ``` 5. 执行以下命令进行配置,确保启用了http_auth_request_module模块: ``` ./configure --with-http_auth_request_module ``` 6. 执行以下命令编译并安装Nginx: ``` make sudo make install ``` 7. 配置Nginx的配置文件(通常是位于 /etc/nginx/nginx.conf)。在合适的位置添加以下配置项: ``` location / { auth_request /auth; ... } location = /auth { internal; proxy_pass http://auth_backend; ... } ``` 这里的 "/auth" 是用来处理认证请求的URL,你可以根据需要进行修改。"http://auth_backend" 是实际处理认证请求的后端服务地址,也需要根据实际情况进行修改。 8. 保存并关闭配置文件后,重启Nginx服务: ``` sudo service nginx restart ``` 现在,你已经成功地添加了http_auth_request_module模块Nginx中。你可以根据实际需求进一步配置和使用该模块来进行认证授权操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值