模块 ngx_http_auth_request_module
| auth_request auth_request_set 的配置 Directives 示例 |
这ngx_http_auth_request_modulemodule (1.5.4+) 实现
client 授权。
如果子请求返回 2xx 响应码,则允许访问。
如果返回 401 或 403,则
访问被拒绝,并显示相应的错误代码。
子请求返回的任何其他响应代码都被视为错误。
对于 401 错误,客户端还会收到 “WWW-Authenticate” 标头。
这个模块不是默认构建的,它应该使用--with-http_auth_request_moduleconfiguration 参数。
该模块可以与 其他访问模块,例如 ngx_http_access_module、ngx_http_auth_basic_module、 以及 ngx_http_auth_jwt_module, 通过 satisfy Directives。
在 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;
}
Directives
| 语法: |
auth_request |
|---|---|
| 默认值: |
auth_request off; |
| 上下文: |
http,server,location |
根据子请求的结果启用授权,并将 子请求将发送到的 URI。
| 语法: |
auth_request_set |
|---|---|
| 默认值: | — |
| 上下文: |
http,server,location |
设置请求variable到给定的value授权请求完成后。
该值可能包含来自授权请求的变量,
如$upstream_http_*.