You can use the `auth_request` module in NGINX to create a subrequest to an HTTP service that does authentication and/or dynamic routing.
The subrequest can return response headers that are available in `$upstream_http_*` variables, which can br used to dynamically route the original request.
http://nginx.org/en/docs/http/ngx_http_auth_request_module.h...