Jenkins Https reverse proxy configuration is not working in centos

Viewed 340

I have installed nginx and jenkins server in centos. I want to connect my jenkins server with https. so I have configured reverse-proxy. But its not working, I'm getting the following error

enter image description here

Below are the my configuration values

File - /etc/nginx/sites-enabled/default

server {
listen 80;
return 301 https://$host$request_uri;

}

server {

    listen 443;
    server_name 134.68.44.235;

    ssl_certificate           /etc/nginx/cert.crt;
    ssl_certificate_key       /etc/nginx/cert.key;

    ssl on;
    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;

    access_log            /var/log/nginx/jenkins.access.log;

    location / {

      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_set_header        X-Forwarded-Proto $scheme;

      # Fix the “It appears that your reverse proxy set up is broken" error.
      proxy_pass          http://localhost:8080;
      proxy_read_timeout  90;

      proxy_redirect      http://localhost:8080 https://134.68.44.235;
    }
  }

File /etc/default/jenkins

JENKINS_ARGS="--webroot=/var/cache/jenkins/war --httpListenAddress=127.0.0.1 --httpPort=$HTTP_PORT -ajp13Port=$AJP_PORT"

Note : I can able to access the jenkins site using http://134.68.44.235:8080

But I can't able access it using https, I installed certificates and followed the steps from this article I'm not sure what I'm missing, Anyone kindly advise me on this.

1 Answers

This snippet below should work well, you'll have to edit the content sections to match the FQDN or IP you want Jenkins to serve the web UI, together with the valid SSL CERT path and SSL KEY path if you want to provide https.

upstream app_server {
  server 127.0.0.1:8080 fail_timeout=3;
}

server {
  listen 80;
  server_name <FQDN OR IP>;
  return 301 https://$server_name$request_uri;
}

server {
  listen 443;
  server_name <FQDN OR IP>;

  ssl on;
  ssl_certificate      /<PATH>/<TO>/<YOUR SSL CERT>;
  ssl_certificate_key  /<PATH>/<TO>/<YOUR SSL KEY>;
  ssl_protocols        SSLv3 TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers          RC4:HIGH:!aNULL:!MD5;
  ssl_prefer_server_ciphers on;
  ssl_session_cache    shared:SSL:10m;
  ssl_session_timeout  10m;

  # Redirect any /* request to port 8080
  location / {
    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_set_header        X-Forwarded-Proto $scheme;

   if ($request_method = 'GET') {
     add_header 'Access-Control-Allow-Origin' '*';
     add_header 'Access-Control-Allow-Headers' '*';
     add_header 'Access-Control-Allow-Methods' 'GET, POST';
     add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range,Location';
   }

    proxy_redirect http:// https://;
    proxy_pass     http://app_server;
  }
}
Related