Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx reverse proxy images and css are not loaded

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/;
    }
like image 975
Richard Avatar asked Aug 07 '14 16:08

Richard


2 Answers

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.

like image 105
Semih Okan Pehlivan Avatar answered Sep 23 '22 02:09

Semih Okan Pehlivan


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

like image 21
Richard Avatar answered Sep 20 '22 02:09

Richard