11
votes

I try to configure an nginx reverse proxy to access a Jenkins instance. I can open the authentication page but there is no CSS and no image. It works perfectly when direct access.

All works as if the reverse proxy does not rewrite correctly URLs defined in the html source page. Have I missed something ?

Here is my nginx configuration :

    location /jenkins {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect false;
            proxy_pass http://jenkins:8080/;
    }
3

3 Answers

9
votes

I found the solution. The nginx reverse proxy works well but Jenkins need some customization to work with reverse proxy.

The final nginx configuration :

    location /jenkins/ {
    proxy_pass http://jenkins:8080/jenkins/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

And the tutorial to configure jenkins behind nginx reverse proxy which solved my problem

6
votes

I don't know if above statement worked for OP but I know that altering location name line did the trick for me:

  location ^~ /jenkins/ {
    proxy_pass http://jenkins:8080/jenkins/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
0
votes

If you use the Jenkins with docker. You can add the environment part of compose file as below:

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

in the nginx conf file. proxy_pass must refer to the http://IP-ADDRESS:PORT/jenkins/. As mentioned before, the link as a reference is very usefull.