Nginx - Rewrite URL and keep basic auth

I am facing the same issue. proxy_pass throws an SSL handshake timeout as my nginx does not have a certificate authority to evaluate the target domain/server.

Rewrite or return 301 does not work because the auth headers are stripped away. But strangely enough, if I try this with two nginx containers running in my localhost I was able to notice that the auth headers remained intact. The problem of auth headers vanishing comes up when trying to rewrite to a remote host.

I got over this problem by using a lambda that forcefully inserts auth info but it's not a good way.