Skip to content

Instantly share code, notes, and snippets.

@rabin-io
Last active August 22, 2023 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rabin-io/2fa12de5f3d134641a5bb667f4b99c25 to your computer and use it in GitHub Desktop.
Save rabin-io/2fa12de5f3d134641a5bb667f4b99c25 to your computer and use it in GitHub Desktop.
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