3

I am trying to run Jenkins behind nginx. Jenkins runs in a Docker container, listening on Port 8080 from directory /jenkins. My nginx container has this Jenkins container linked as hostname "jenkins", so in its context, Jenkins is accessible via http://jenkins:8080/jenkins.

I followed the steps at Running Jenkins from a folder with TLS encryption and thus my site-config contains this:

location ^~ /jenkins/ {
    sendfile off;
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_pass http://jenkins:8080/jenkins/;
    proxy_redirect http:// https://;
    proxy_max_temp_file_size 0;
    client_max_body_size       64m;
    client_body_buffer_size    128k;
    proxy_connect_timeout      90;
    proxy_send_timeout         90;
    proxy_read_timeout         90;
    proxy_buffer_size          4k;
    proxy_buffers              4 32k;
    proxy_busy_buffers_size    64k;
    proxy_temp_file_write_size 64k;
  }

I am now trying to access the nginx from localhost, and calling https://localhost/jenkins presents me Jenkins. However, when I go to "Manage Jenkins", I get the message that my reverse proxy setup is incorrect. I tried

curl -k -iL -e https://localhost/jenkins/manage \
   https://localhost/jenkins/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/test

which gives me a 404 with http://localhost/jenkins/manage vs. https:.

When I add

    proxy_set_header   X-Forwarded-Proto  https;
    proxy_set_header   X-Forwarded-Port 443;
    proxy_set_header   X-Forwarded-Ssl on;

the message changes to https://localhost/jenkins/manage vs. https:

What am I missing?

  • When you use curl do you get a value for the Location: response header? This might help you add a more specific proxy_redirect parameter. – Richard Smith Dec 15 '15 at 11:26
  • curl -vvv -k -iL -e https://localhost/jenkins/manage https://localhost/jenkins/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/test 2>&1 |grep Location gives me: < Location: https://localhost/jenkins/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/testForReverseProxySetup/https%3A%2F%2Flocalhost%2Fjenkins%2Fmanage/ Location: https://localhost/jenkins/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/testForReverseProxySetup/https%3A%2F%2Flocalhost%2Fjenkins%2Fmanage/ - what does this tell me? – rabejens Dec 15 '15 at 11:58
  • The proxy_redirect seems to be functioning correctly. – Richard Smith Dec 15 '15 at 12:19
  • I think I found something interesting. The redirect seems to chop off slashes at some point. When I call: curl -k -iL -e https://localhost/jenkins/manage https://localhost/jenkins/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/testForReverseProxySetup/a I get https://localhost/jenkins/manage vs. a, however, with .../testForReverseProxySetup/a/b, I also get ... vs a. Same with ...a%2Fb. Any ideas? – rabejens Dec 15 '15 at 12:28
  • Very strange: I now configured Jenkins and am playing around with it, and did not notice any strange behaviour yet. Plus: When I run this curl on my other internal Jenkins which only listens on http, I get the same 404, but I have been running it for over a year without any problems now. – rabejens Dec 15 '15 at 13:22
6

I had a problem like this just now, and what solved it for me was described in https://stackoverflow.com/a/20514632/1446479

My NOT working config used this line:

proxy_pass http://127.0.0.1:8015/jenkins/;

But my working config now looks like this:

location /jenkins/
{
  proxy_pass http://127.0.0.1:8015$request_uri;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-for $remote_addr;
  port_in_redirect off;
  proxy_redirect http://my.host/jenkins /jenkins;
  proxy_connect_timeout 300;
}
  • this doesn't work for me. I get bad gateway (even when updating my.host and proxy_pass IP address and port – 7wp Nov 26 '18 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.