Nginx中请求的顺序stream

我有一个场景,当一个实际的请求之前,服务器需要做授权请求。 所以,一个请求由两个不同的服务来服务。

Nginx的位置必须由Auth-Service来处理,如果响应状态是200 OK,则请求应该被转发到Feature-Service。 否则,如果响应状态401,那么这个状态应该被回复到​​前端。

upstream auth_service { server localhost:8180; } upstream feature_service { server localhost:8080; } location /authAndDo { # suggest here } 

特别是为了这个目的, http://nginx.org/r/auth_request通过http://nginx.org/docs/http/ngx_http_auth_request_module.html (不是默认生成)存在。

它可以让你通过子请求把authentication放到你想要的任何位置,从而有效地将authentication从实际资源中分离出来。