title: Jenkins: How to configure Jenkins behind Nginx reverse proxy for JNLP slaves to connect
body: <p>I am trying to set up a Jenkins master and a Jenkins slave node where the Jenkins Master is behind Nginx reverse proxy on a different server with SSL termination. The nginx configuration is as following:</p>
  
  <pre><code>upstream jenkins {
    server &lt;server ip&gt;:8080 fail_timeout=0;
  }
  
  server {
    listen 443 ssl;
    server_name jenkins.mydomain.com;
    ssl_certificate /etc/nginx/certs/mydomain.crt;
    ssl_certificate_key /etc/nginx/certs/mydomain.key;
  
    location / {
      proxy_set_header        Host $host:$server_port;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto $scheme;
      proxy_redirect          http:// https://;
      proxy_pass              http://jenkins;
    }
  }
  
  server {
    listen 80;
    server_name jenkins.mydomain.com;
    return 301 https://$server_name$request_uri;
  }
  </code></pre>
  
  <p>The TCP port for JNLP agents is set as 50000 in Jenkins master Global Security configuration. Port 50000 is set to be accessible from anywhere on the host machine.</p>
  
  <p>The JNLP slave is launched with the following command:</p>
  
  <pre><code>java -jar slave.jar -jnlpUrl https://jenkins.mydomain.com/computer/slave-1/slave-agent.jnlp -secret &lt;secret&gt;
  </code></pre>
  
  <p>The JNLP slave fails to connect to the configured JNLP port on the master:</p>
  
  <pre><code>INFO: Connecting to jenkins.mydomain.com:50000 (retrying:4)
  java.net.ConnectException: Connection timed out
          at java.net.PlainSocketImpl.socketConnect(Native Method)
          at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
          at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
          at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
          at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
          at java.net.Socket.connect(Socket.java:589)
          at java.net.Socket.connect(Socket.java:538)
          at hudson.remoting.Engine.connect(Engine.java:400)
          at hudson.remoting.Engine.run(Engine.java:298)
  </code></pre>
  
  <p>What is the configuration required for the JNLP slave to connect to the Jenkins master?</p>