模組 ngx_http_auth_basic_module

範例設定
指令
     auth_basic
     auth_basic_user_file

ngx_http_auth_basic_module 模組允許使用「HTTP 基本身份驗證」協定驗證使用者名稱和密碼,以限制對資源的存取。

也可以透過位址、透過子請求的結果或透過JWT來限制存取。同時透過位址和密碼限制存取由 satisfy 指令控制。

範例設定

location / {
    auth_basic           "closed site";
    auth_basic_user_file conf/htpasswd;
}

指令

語法 auth_basic string | off;
預設值
auth_basic off;
上下文 http, server, location, limit_except

啟用使用「HTTP 基本身份驗證」協定驗證使用者名稱和密碼。指定的參數用作 realm。參數值可以包含變數 (1.3.10, 1.2.7)。特殊值 off 取消從先前的組態層級繼承的 auth_basic 指令的效果。

語法 auth_basic_user_file file;
預設值
上下文 http, server, location, limit_except

指定一個檔案,其中保留使用者名稱和密碼,格式如下

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

file 名稱可以包含變數。

支援以下密碼類型