Proxy_redirect vs. relative URLs from upstream

Hi,

I’m trying to create a sinle proxying configuration as following:

location = /proxy {
resolver 8.8.8.8;
proxy_pass $args;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect “” $uri?;
}

e.g. http://example.com/proxy?http://example2.com/ would deliver the
contents/headers of http://example2.com/ . If http://example2.com/
replies
with

Location: http://example3.com/

, the client gets

Location: http://example.com/proxy?http://example3.com/

, so it works as expected. However, i’ve got example2.com replying with
relative Location, e.g.:

Location: /some/path

This results in client getting:

Location: http://example.com/proxy?/some/path

, something that won’t work. Is there any way to make it work for client
to
get

Location: http://example.com/proxy?http://example2.com/some/path

?