14

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 Answers 3

10

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

Sign up to request clarification or add additional context in comments.

2 Comments

Glad this worked for you. Feel free to click the green checkbox and mark this answer as 'Accepted' to let everyone else know the problem has been solved :)
This helped me, but I am running it behind Apache. Particularly the part about "make sure you add a slash at the end of all URLs in proxy params in apache".
6

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;
    }

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.