Nginx: Is it possible to get response retuned from

2020-07-06 05:51发布

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条回答
等我变得足够好
2楼-- · 2020-07-06 06:27

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.

查看更多
登录 后发表回答