nginx反向代理图像和css未加载

Ric*_*ard 7 proxy reverse-proxy nginx

我尝试配置一个nginx反向代理来访问Jenkins实例.我可以打开身份验证页面,但没有CSS,也没有图像.直接访问时它非常有效.

所有工作都好像反向代理不会正确重写html源页面中定义的URL.我错过了什么吗?

这是我的nginx配置:

    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/;
    }
Run Code Online (Sandbox Code Playgroud)

Ric*_*ard 6

我找到了解决方案.nginx反向代理运行良好,但Jenkins需要一些自定义来使用反向代理.

最终的nginx配置:

    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;
    }
Run Code Online (Sandbox Code Playgroud)

并在nginx反向代理后面配置jenkins 的教程解决了我的问题

  • 这对我有帮助,但我[在 Apache 后面运行它](https://wiki.jenkins-ci.org/display/JENKINS/Running+Jenkins+behind+Apache)。特别是关于“确保在 apache 中的代理参数中的所有 URL 末尾添加斜杠”的部分。 (2认同)

dzh*_*zhi 5

我不知道上面的声明是否适用于OP,但我知道更改位置名称行对我来说很有用:

  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;
    }
Run Code Online (Sandbox Code Playgroud)