Proxy Pass based on the first field in the URI

j94305 nginx-forum at
Wed Sep 11 15:55:45 UTC 2019

Try something like this:

map $urlprefix $urlproxy {
  "foo" "";
  "bar" "";
  "fie" "";
  default "";


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.


Posted at Nginx Forum:,285607,285609#msg-285609

More information about the nginx mailing list