how to handle nginx reverse proxy https to http scheme redirect how to handle nginx reverse proxy https to http scheme redirect jenkins jenkins

how to handle nginx reverse proxy https to http scheme redirect


Ok, I was having the same problem and after some more research and couple of trial and error attempts I figured it out.

Try adding the header X-Forwarded-Proto as in the following example,

server {    server_name example.com;    proxy_set_header Host $host;    # You need this line    proxy_set_header X-Forwarded-Proto $scheme;    location ^~ /jenkins {        proxy_pass http://localhost:8080/;    }    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;}


You probably need to rewrite the 302 redirect from upstream. Assuming everything else is correct, try:

proxy_redirect http:// https://;

See this document for details.


I was unable to use the proxy-redirect, rewrite and return directives to implement the behavior I was looking for. Setting up jenkins to use https solved the problem.