Jenkins with reverse proxy to alternative port number Jenkins with reverse proxy to alternative port number jenkins jenkins

Jenkins with reverse proxy to alternative port number


Update the following lines in your Update 4 configuration:

listen 443 default ssl http2;proxy_set_header        Host $host:9090;


This is usually due to the proxy_redirect being at set at an incorrect value (most often people try to change it from the default value of default, making stuff not work).

I'm not sure I understand your config — why is your listen directive only mentions 443, without any mentions of 9090, yet in proxy_redirect you're doing a replacement for 9090?

You should probably set proxy_redirect to the default value of default, setup listen correctly (instead of doing redirections through the firewall?), and then the problems will likely go away.


If the above doesn't help, then you'd have to find out what Location jenkins provides when it replies to the requests from nginx, and specify such prefix within the proxy_redirect directive. I would recommend something like sudo tcpdump -A -ilo port 8080 whilst executing the curl query as above to find out exactly what it is that Jenkins returns, to make sure to account for all the extra variables when the requests are made from within nginx, like the extra X- headers and such.


If all else fails and you don't really care for hairy configs, and you know that you don't plan to redirect to any foreign hosts from within this jenkins server, then perhaps something like the following is worth a try as well:

proxy_redirect ~^https?://[^/]+/(?<u>.*)$ https://jenkins.example.com:9090/$u;

(Or, of course, you could also use some extra regular expressions, depending on what it is that jenkins returns in its Location headers back to nginx.)

However, just to make sure people don't copy-paste the above without reading all the prior disclaimers, let's reiterate that the real advice is still as follows:

proxy_redirect default;


Step 1: change listen 443 ssl spdy; to listen 9090 ssl spdy;

Step 2: change proxy_pass http://127.0.0.1:8080/; to proxy_pass http://127.0.0.1:8080;

I might also try getting rid of those weird headers in lines 4 & 5, but that's just a guess.

If this doesn't work, I'd start again from scratch alongside reading the Digital Ocean tutorial, it's really good.

It throws me a lot that you're listening on port 443 with nginx but expecting it to serve on port 9090. In all likelihood, when you curl 9090, you're accessing jenkins directly. Either that or you copy-pasted the wrong block in SO.

Anyways, you probably need to get clearer on which server is serving on which port, and the order requests come through. In my mind, it should be one of these two:

1) https://jenkins.example.com:9090 goes to nginx listening on port 9090, which proxies it to jenkins, which is at http(s)://127.0.0.1:8080 (different app, same server).

2) https://jenkins.example.com goes to nginx listening on port 443, which proxies it to jenkins, which is at http(s)://127.0.0.1:9090.