How to do NGINX Rewrite + Proxy_Pass from one server block to another

I am got basic NGINX knowledge and was task with something beyond my knowledge.

We have one nginx server configured with two different server blocks: and When request hit either server is will be forwarded the request to it's respective backend server. Mostly API calls.

There was a big bug introduced to backend code causing issues and I was tasked to come up with a workaround in NGINX while they are working on a fix.

Problem: The code is sending request to "" but this url does not exist and it should go to "".

Plan was to go into the server block create a new location matching the wrong uri and use rewrite + proxy pass to send the traffic to the right place. I've been trying all sort of stuff and got couple other guys helping but they got different ideas. I enabled rewrite logs and I do see that the matched and rewritten are correct, but the problem is that is forwarding the traffic from to Keeps getting error "No such file or directory"

here is the rewrite block:

location ~* ^v1/service/(.*){
   set $match1 $1;
   rewrite ^/v1/service/(.*)$ /api/service/v1/$match1$is_args$args last;

Please let me know if this is possible or if there is a better alternative.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum