Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Jenkins - Nginx Reverse Proxy Configuration

Below is my working Nginx site configuration for reverse proxying my Jenkins deployment. I ended up having to strip out my default proxy configuration stuff, and copying as much as possible from the Jenkins docs. I am posting this to help prevent me having to go through the same pain ever again.

server {
    listen 80;
    server_name jenkins.mydomain.com;
    return 302 https://jenkins.mydomain.com$request_uri;
}


server {
    listen 443 ssl;

    ssl on;

    server_name jenkins.mydomain.com;

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

    ssl_certificate      ssl/jenkins.mydomain.com/fullchain.pem;
    ssl_certificate_key  ssl/jenkins.mydomain.com/privkey.pem;

    ssl_protocols        TLSv1.2;
    ssl_ciphers RC4:HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
    keepalive_timeout    60;
    ssl_session_cache    shared:SSL:10m;
    ssl_session_timeout  10m;


    location / {

      sendfile off;
      proxy_pass         http://192.168.0.28:8080;

      proxy_redirect     default;
      proxy_http_version 1.1;

      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;
      proxy_set_header   X-Forwarded-Port  443;
      proxy_max_temp_file_size 0;

      #this is the maximum upload size
      client_max_body_size       10m;
      client_body_buffer_size    128k;

      proxy_connect_timeout      90;
      proxy_send_timeout         90;
      proxy_read_timeout         90;
      proxy_buffering            off;
      proxy_request_buffering    off; # Required for HTTP CLI commands in Jenkins > 2.54
      proxy_set_header Connection ""; # Clear for keepalive
    }
}

Be sure to change jenkins.mydomain.com to whatever your FQDN is, and the IP address of 192.168.0.28 to whatever is appropriate for you.

References

Last updated: 17th July 2023
First published: 25th October 2022

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch