Nginx密码验证 ngx

it2022-05-09  17

有时候我们需要限制某些目录只允许指定的用户才可以访问,我们可以给指定的目录添加一个用户限制。 nginx给我们提供了ngx_http_auth_basic_module模块来实现这个功能。 模块ngx_http_auth_basic_module允许使用“HTTP基本认证”协议验证用户名和密码来限制对资源的访问。

location / { auth_basic "closed site"; auth_basic_user_file conf/htpasswd;} 语法: auth_basic string | off; 默认值: auth_basic off; 上下文: http, server, location, limit_except 开启使用“HTTP基本认证”协议的用户名密码验证。 指定的参数被用作 域。 参数off可以取消继承自上一个配置等级 auth_basic 指令的影响。语法: auth_basic_user_file file; 默认值: — 上下文: http, server, location, limit_except 指定保存用户名和密码的文件,格式如下: # commentname1:password1name2:password2:commentname3:password3

密码应该使用crypt()函数加密。 可以用Apache发行包中的htpasswd命令来创建此类文件。

来自为知笔记(Wiz)

转载于:https://www.cnblogs.com/snifferhu/p/6148900.html


最新回复(0)