【Nginx】Auth 认证

配置示例

location / {
    auth_basic           "my site";
    auth_basic_user_file /etc/nginx/htpasswd;
}

指令说明

auth_basic

语法: auth_basic string | off;
默认值: auth_basic off;
上下文: http,server,location,limit_except

开启使用“HTTP基本认证”(HTTP Basic Authentication)协议的用户名密码验证。
指定的参数被用作域。
参数可以包含变量(1.3.10,1.2.7)。
参数off可以取消继承自上一个配置等级auth_basic指令的影响。
参数off表示不开启HTTP基本认证。

auth_basic_user_file

引入认证的密码文件

语法: auth_basic_user_file <filepath>;
默认值: —
上下文: http,server,location,limit_except

生成密码文件 htpasswd

[root@/etc/nginx/ ~]# htpasswd -bdc htpasswd admin 12345
Adding password for user admin

[root@/etc/nginx/ ~]# cat htpasswd
admin:PbSRr7orsxaso

验证HTTP基本认证

curl -u username:password URL

示例:
curl -u admin:12345 http://127.0.0.1
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章