Nginx:是否有可能从auth_request重新获得响应

out*_*dev 8 authentication nginx

我正在为nginx使用auth模块.(http://nginx.org/en/docs/http/ngx_http_auth_request_module.html)是否有可能以某种方式存储来自/ auth的响应,因此我可以将其作为请求主体发送到另一个端点.

location /private/ {
    auth_request /auth;
    proxy_pass ... 
    proxy_set_body 'Here I want to put /auth response. How?';
}

location = /auth {
    proxy_pass ...
}
Run Code Online (Sandbox Code Playgroud)

Max*_*nin 18

简短回答:

不,你不能.

答案很长:

你不能得到回复的身体auth_request.您可以使用auth_request_set指令获取响应中返回的标头:

location / {
    auth_request /auth;
    auth_request_set $auth_foo $upstream_http_foo;
    proxy_pass ...
    proxy_set_body $auth_foo;
}
Run Code Online (Sandbox Code Playgroud)

上面的配置将$auth_foo变量设置为Fooauth子请求的标头值.