模块 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 配置参数启用。
该模块可以与其他访问模块(如 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_*。
