1

I have a standalone Jenkins which can be reached at http://1.2.3.4:8080, and setup a Nginx instance working on 80 port.

Here is my config file for Nginx:

location /jenkins {
    proxy_pass http://127.0.0.1:8080/;
}

By visit http://1.2.3.4/jenkins I can reach to Jenkins, but static resources for Jenkins like css, images did not loaded. I can reach these static resources by http://1.2.3.4/jenkins/resource.css ...

How should I correct my Nginx config file to make Jenkins behind Nginx reverse proxy work?

Nginx version: 1.12.2 Jenkins version: jenkins-2.89.1-1.1.noarch.rpm

xring
  • 727
  • 2
  • 8
  • 29

3 Answers3

1

I got the answer, I'm using CentOS7, add JENKINS_ARGS="--prefix=/jenkins" to /etc/sysconfig/jenkins and restart Jenkins worked.

xring
  • 727
  • 2
  • 8
  • 29
0

set an enviroment variable

JENKINS_OPTS="--prefix=/jenkins"

in docker-compose file it will be something like this:

  environment:
      - JENKINS_OPTS="--prefix=/jenkins"
0

I have never experienced CentOS but I had the same issue with Ubuntu

Problem: I wanted to make my nginx to so that I can access jenkins with my own host under https://my-host/jenkins

I did lots of online digging and the majority of the answers were adding "--prefix=/jenkins" to JENKINS_ARGS in /etc/default/jenkins file, then restart jenkins service. But this solution didn't work for me.

Spent hours of more research and tries, I finally made it work with this solution.

Solution:

nginx side: #etc/nginx/sites-available/default

location /jenkins/ {
    proxy_pass HTTP://localhost:1234/jenkins/;
    ...
}

jenkins side:

Major Credit: Jihed Hmida & Priit: Jenkins changes in /etc/default/jenkins not working

after jenkins 2.332.1.. the /etc/default/jenkins is no longer used. jenkins is now configured with systemd. you can check systemctl cat jenkins to see the options and systemctl edit jenkins to modify it..

To set prefix arg '/jenkins' to jenkins service, you have to add Environment="JENKINS_PREFIX=/jenkins" to sudo systemctl edit jenkins

You can also see many other options in sudo systemctl cat jenkins

Don't forget to restart both nginx and jenkins services :)

KanG98
  • 11
  • 1