ngx_http_auth_request_module

ngx_http_auth_request_module 模块(1.5.4+)基于子请求结果实现客户端授权。如果子请求返回一个 2xx 响应代码,则允许访问。如果返回 401 或 403,则拒绝访问并抛出相应的错误代码。子请求返回的任何其他响应代码被认为是一个错误。

对于 401 错误,客户端也从子请求响应中接收 WWW-Authenticate 头。

该模块不是默认构建,应该在构建时使用 --with-http_auth_request_module 配置参数启用。

该模块可以通过 satisfy 指令与其他访问模块(如 ngx_http_access_modulengx_http_auth_basic_modulengx_http_auth_jwt_module)进行组合。

在 1.7.3 版本之前,无法缓存对授权子请求的响应(使用 proxy_cacheproxy_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;
}
1
2
3
4
5
6
7
8
9
10
11

指令

auth_request

-说明
语法auth_request uri | off;
默认auth_request off;
上下文http、server、location

启用基于子请求结果的授权,并设置发送子请求的 URI。

auth_request_set

-说明
语法auth_request_set $variable value;;
默认——
上下文http

在授权请求完成后,将请求 variable(变量)设置为给定的 value(值)。该值可能包含授权请求中的变量,例如 $upstream_http_*

原文档

http://nginx.org/en/docs/http/ngx_http_auth_request_module.htmlopen in new window

Last Updated: 10/19/2021, 2:11:05 PM
Contributors: frisktale