NGINX proxy_pass with URI modification

Solution 1:

From nginx's documentation (context : prefixed location)

If the proxy_pass directive is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive.

So it can be simplified with the following :

location /jazz/ {
    proxy_pass http://vito_api/;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Solution 2:

I know this is an old question but I was looking for this and found another and I belive the easiest solution. While using proxy_pass you can't use uri however you can use it as variable. Like here:

location  ~ ^/app/(.*)$ {
# proxy_pass   http://127.0.0.1/some_dir;       # error
proxy_pass   http://127.0.0.1/some_dir/$1;      # ok
}