Prevent nginx from redirecting traffic from https to http when used as a reverse proxy

Well, I got a bit of inspiration and tried:

proxy_redirect http:// $scheme://;

Which seems to do the trick. This still seems hacky to me, though, so I still welcome any guidance on anything I might be doing wrong or less hacky ways to achieve the same result.


The other solution is to indicate to the upstream whether the request is HTTP or HTTPS and have it issue the according redirect. Adding this in the nginx config would set a header for the upstream to inspect.

proxy_set_header    X-Scheme $scheme;