nginx中文文档-ngx_http_auth_request_module

本文介绍ngx_http_auth_request_module模块的相关指令。

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,通过satisfy指令来实现。
在1.7.3版本以前,响应的认证子请求不能被缓存。
实例配置

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 uri | off
默认:auth_request off
上下文: http, server, location

开启基于子请求的权限认证,并设置发送子请求的URI。

auth_request_set

语法:auth_request_set variable value
默认:—
上下文:http, server, location

设置在认证请求完成后给变量设的值。值可以包含认证请求的变量,如$upstream_http_*。