Unfortunately I'm not able to change the behaviour of the upstream servers, these are a closed-source commercial product and come as-is.
I'll look into the proxy_redirect to see if I can preserve the server to redirect to in some way, something like a GET argument or cookie.
I just found out about the Lua module as well. I'm pretty fluent at Lua so I'll see if the module offers the tools to solve my problem - maybe I can forge X-accel-redir headers before Ngix handles the response and trick it into thinking these were generated by upstream.
Thank you,