模块 ngx_http_auth_request_module
配置示例 指令 auth_request auth_request_set |
ngx_http_auth_request_module
模块 (1.5.4+) 基于子请求的结果实现客户端授权。如果子请求返回 2xx 响应码,则允许访问。如果返回 401 或 403,则使用相应的错误码拒绝访问。子请求返回的任何其他响应码都被视为错误。
对于 401 错误,客户端还会收到来自子请求响应的 “WWW-Authenticate” header。
此模块默认不构建,应使用 --with-http_auth_request_module
配置参数启用。
此模块可与其他访问模块结合使用,例如 ngx_http_access_module、ngx_http_auth_basic_module 和 ngx_http_auth_jwt_module,通过 satisfy 指令实现。
在 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_*
。