'Removing location without removing the rest of the path

According to many old posts here and in other places on the internet, the following nginx configuration should proxy http://nginx-service/foo/bar to http://web.default.svc.cluster.local:8080/bar.

In other words, it should strip the /foo part in the path (the location matched) while appending the rest (/bar) when proxying it on.

That is not what I observe in practice; the full path is removed and / is proxied on.

How could I proxy this to the upstream service while keeping /bar?



Solution 1:[1]

You didn't add any config in your question but any of the following should work:

location /foo/ {
  proxy_pass http://web.default.svc.cluster.local:8080/;
}

or

location /foo/bar {
  proxy_pass http://web.default.svc.cluster.local:8080/bar;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Grin