Reputation: 2415
I've tried at least a half a donzen examples on how to get NGINX working with Jenkins. My most recent NGINX configuration is based on the following example:
https://wiki.jenkins.io/display/JENKINS/Running+Jenkins+behind+Nginx
No mater what I try, Jenkins keeps saying It appears that your reverse proxy set up is broken.
I'm hoping someone can spot what is wrong as I have spent hours trying to solve this to no avail.
Thanks!
upstream cicd {
keepalive 32;
server 127.0.0.1:8080;
}
server {
listen 443 ssl;
listen [::]:443 ssl ipv6only=on;
server_name cicd.domain.com;
root /var/run/jenkins/war/;
access_log /var/log/nginx/jenkins/access.log;
error_log /var/log/nginx/jenkins/error.log;
ssl_certificate /etc/letsencrypt/live/cicd.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/cicd.domain.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
#static files
location ~ "^/static/[0-9a-fA-F]{8}\/(.*)$" {
rewrite "^/static/[0-9a-fA-F]{8}\/(.*)" /$1 last;
}
#user content
location /userContent {
root /var/lib/jenkins/;
if (!-f $request_filename){
rewrite (.*) /$1 last;
break;
}
sendfile on;
}
#cicd
location @cicd {
sendfile off;
proxy_pass http://cicd;
proxy_redirect http://localhost:8080 https://cicd.domain.com;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_max_temp_file_size 0;
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;
proxy_set_header Connection "";
}
#optional
location / {
if ($http_user_agent ~* '(iPhone|iPod)') {
rewrite ^/$ /view/iphone/ redirect;
}
try_files $uri @cicd;
}
}
Upvotes: 9
Views: 7038
Reputation: 4734
For Linux (Ubuntu) users, please check the /etc/default/jenkins file.
In that file, look for JENKINS_ARGS and copy the httpListenAddress and paste it in your Jenkins URL.
I am using Nginx with Lets Encrypt encryption and my /etc/default/jenkins file is like this JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT --httpListenAddress=127.0.0.1"
I think you can also localhost:[your port] or 127.0.0.1:[your port]
Upvotes: 0
Reputation: 1757
For me the URL was correctly configured. I had to changed Nginx configuration to include some extra headers:
server {
listen 443 ssl;
server_name my-subdomain.main-domain.com; # this is the url domain of the proxy (Load balancer in front of Jenkins)
ssl_certificate /etc/nginx/certs/ssl_certificate.crt;
ssl_certificate_key /etc/nginx/certs/ssl_key.pem;
location / {
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Host my-subdomain.main-domain.com; # this is the url domain of the proxy (Load balancer in front of Jenkins)
proxy_pass http://${JENKINS_PRIVATE_IP}:${JENKINS_PORT};
}
}
Upvotes: 5
Reputation: 2563
This is not a NGINX problem.
Inside Jenkins you need to configure the Jenkins URL. If it is not set correctly you will get the error you observed.
Check Jenkins -> Manage Jenkins -> Configure System => Jenkins URL.
Upvotes: 17