Module ngx_http_auth_request_module
ngx_http_auth_request_module
模块(1.5.4)基于子请求的结果实现客户端授权。如果子请求返回 2xx 响应代码,则允许访问。如果返回 401 或 403,则使用相应的错误代码拒绝访问。子请求返回的任何其他响应代码都被视为错误。
对于 401 错误,客户端还从子请求响应中接收到“ WWW-Authenticate”Headers。
默认情况下未构建此模块,应使用--with-http_auth_request_module
配置参数启用它。
该模块可以通过satisfy指令与其他访问模块(例如ngx_http_access_module,ngx_http_auth_basic_module和ngx_http_auth_jwt_module)组合。
Note
在版本 1.7.3 之前,无法缓存对授权子请求的响应(使用proxy_cache,proxy_store等)。
Example Configuration
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;
}
Directives
Syntax: | auth_request uri | off; |
Default: | auth_request off; |
Context: | http , server , location |
根据子请求的结果启用授权,并设置将子请求发送到的 URI。
Syntax: | auth_request_set $variable value; |
Default: | — |
Context: | http , server , location |
授权请求完成后,将请求variable
设置为给定的value
。该值可以包含来自授权请求的变量,例如$upstream_http_*
。