how to handle nginx reverse proxy https to http scheme redirect
<p>I have set up nginx as a reverse proxy on an ubuntu instance that is hosting jenkins, and a few other applications.  I'm using nginx to route to the various applications based on a relative path.  All traffic from the client to nginx is over https.  Behind the firewall, nginx routes everything over http to the configured path and port numbers.  It looks something like this:</p>

<pre><code>              firewall
                |
                |
---&gt;https---&gt;nginx---http---&gt;jenkins
                |
                |
</code></pre>

<p>The relevant part of the nginx config file is this:</p>

<pre><code>server {

    listen 443 ssl;

    ssl_certificate cert.crt;
    ssl_certificate_key cert.key;
    ssl_session_cache builtin:1000 shared:SSL:10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;


    location /jenkins {

            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            proxy_pass http://127.0.0.1:6969;
    }

}
</code></pre>

<p>The problem is that jenkins uses a simple authentication, and upon a successful login, it sends a 302 redirect.  Nginx correctly proxies the url and port, but not the scheme.  So the client follows the redirect over http, instead of https.  In the browser I then get a 400 error:</p>

<pre><code>400 Bad Request The plain HTTP request was sent to HTTPS port
</code></pre>

<p>I know that there is a scheme variable: $scheme.  But I don't know how to tell nginx to map the http redirect from jenkins to https.  All the <a href="https://stackoverflow.com/q/27320460/906048">examples</a> I've looked at on stackoverflow seem to address slightly different situations.    </p>