Skip to content

Instantly share code, notes, and snippets.

@rabin-io
Created Nov 16, 2021
Embed
What would you like to do?
NGINX config as reverse-proxy for Jenkins
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name jenkins.example.com;
root /var/lib/jenkins/war;
# SSL
ssl_certificate /etc/ssl/jenkins.example.com.crt;
ssl_certificate_key /etc/ssl/jenkins.example.com.key;
# logging
access_log /var/log/nginx/jenkins.example.com.access.log;
error_log /var/log/nginx/jenkins.example.com.error.log info;
# index.php
index index.php;
ignore_invalid_headers off;
location ~ "^/static/[0-9a-fA-F]{8}\/(.*)$" {
# rewrite all static files into requests to the root
# E.g /static/12345678/css/something.css will become /css/something.css
rewrite "^/static/[0-9a-fA-F]{8}\/(.*)" /$1 last;
}
location /userContent {
# have nginx handle all the static requests to userContent folder
# note : This is the $JENKINS_HOME dir
root /var/lib/jenkins/;
if (!-f $request_filename){
# this file does not exist, might be a directory or a /**view** url
rewrite (.*) /$1 last;
break;
}
sendfile on;
}
# reverse proxy
location / {
proxy_pass http://127.0.0.1:8080;
include nginxconfig.io/proxy.conf;
proxy_request_buffering off; # Required for HTTP CLI commands
proxy_set_header Connection ""; # Clear for keepalive
add_header x-location "/";
}
}
# subdomains redirect
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name *.jenkins.example.com;
# SSL
ssl_certificate /etc/ssl/jenkins.example.com.crt;
ssl_certificate_key /etc/ssl/jenkins.example.com.key;
return 301 https://jenkins.example.com$request_uri;
}
# HTTP redirect
server {
listen 80;
listen [::]:80;
server_name .jenkins.example.com;
return 301 https://jenkins.example.com$request_uri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment