Try something like this:
map $urlprefix $urlproxy {
"foo" "https://foohost.foo.com";
"bar" "http://barhost.blah.com";
"fie" "https://fie.special.domain.com/blubb";
default "https://standard.com";
}
[...]
location ~ "^/(?<urlprefix>[^/]+)(?<urlsuffix>/.*)$" {
[...]
proxy_pass "$urlproxy$urlsuffix$is_args$args";
[...]
}
You can dynamically determine the host (including a URL piece, if necessary) with the "map", and use the mapped proxy prefix then in the proxy_pass directive. If whatever lies beyond the NGINX requires URL arguments, don't forget the $is_args$args part.
--j.