Nginx: Is it possible to get response retuned from

2020-07-06 05:48发布

问题:

I am using auth module for nginx. (http://nginx.org/en/docs/http/ngx_http_auth_request_module.html) Is it possible somehow to store the response from the /auth, so I can send it as a request body to another endpoint.

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

location = /auth {
    proxy_pass ...
}

回答1:

Short answer:

No, you can't.

Long answer:

You can't get body of a response returned to auth_request. You can get a header returned in the response though, using the auth_request_set directive:

location / {
    auth_request /auth;
    auth_request_set $auth_foo $upstream_http_foo;
    proxy_pass ...
    proxy_set_body $auth_foo;
}

The above configuration will set the $auth_foo variable to the value of Foo header of an auth subrequest.