模組 ngx_http_auth_request_module
範例配置 指令 auth_request auth_request_set |
ngx_http_auth_request_module
模組 (1.5.4+) 根據子請求的結果實作用戶端授權。如果子請求返回 2xx 回應碼,則允許存取。如果返回 401 或 403,則拒絕存取並返回相應的錯誤碼。子請求返回的任何其他回應碼都被視為錯誤。
對於 401 錯誤,用戶端也會收到來自子請求回應的「WWW-Authenticate」標頭。
此模組預設不建置,應使用 --with-http_auth_request_module
配置參數啟用。
此模組可以透過 satisfy 指令與其他存取模組結合使用,例如 ngx_http_access_module、ngx_http_auth_basic_module 和 ngx_http_auth_jwt_module。
在 1.7.3 版本之前,對授權子請求的回應無法被快取(使用 proxy_cache、proxy_store 等)。
範例配置
location /private/ { auth_request /auth; ... } location = /auth { proxy_pass ... proxy_pass_request_body off; proxy_set_header Content-Length ""; proxy_set_header X-Original-URI $request_uri; }
指令
語法 |
auth_request |
---|---|
預設值 |
auth_request off; |
上下文 |
http , server , location |
根據子請求的結果啟用授權,並設定將發送子請求的 URI。
語法 |
auth_request_set |
---|---|
預設值 | — |
上下文 |
http , server , location |
在授權請求完成後,將請求的 variable
設定為給定的 value
。該值可能包含來自授權請求的變數,例如 $upstream_http_*
。