【问题标题】:Jenkins behind nginx without subdirectory没有子目录的 nginx 后面的 Jenkins
【发布时间】:2014-02-28 18:28:45
【问题描述】:

我在 Glassfish 安装中运行了 Jenkins,因此可以联系到 Jenkins @

http://localhost:8090/jenkins/

我设法设置了 nginx,以便可以从外部访问 Jenkins @

http://build.example.com/jenkins/

到目前为止,此设置运行良好,但我对此并不满意。我真正想要达到的目标是击中

http://build.example.com

在浏览器中访问 Jenkins。

这是我当前的 nginx 配置:

server {
    listen   80;

    server_name build.example.com;

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

我希望这可以通过一些 url 重写来实现,但我完全不知道该怎么做......

【问题讨论】:

    标签: nginx url-rewriting jenkins reverse-proxy


    【解决方案1】:

    然后改变:

    proxy_pass http://localhost:8090;
    

    proxy_pass http://localhost:8090/jenkins/;
    

    参考:http://nginx.org/r/proxy_pass

    【讨论】:

    • 不幸的是,这似乎不是那么容易,因为 jenkins 以http://build.example.com/jenkins/static/... 的形式创建了很多链接,然后导致 404
    • Nginx 无法对后端创建的所有链接做任何事情。在这种情况下,您应该修复您的后端。
    【解决方案2】:

    在我看来问题出在 Glassfish 配置上。

    如何在application.xml 中设置以下值:

    <context-root/>
    

    而不是默认名称,即 WAR 文件的名称,不带 .war 扩展名。

    SO 上似乎有similar questions

    【讨论】:

      【解决方案3】:

      来自http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

      location / {
          rewrite    /jenkins/(.*) /$1 break;
          proxy_pass http://localhost:8090/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;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-04-25
        • 1970-01-01
        • 2018-04-29
        • 2016-01-09
        • 2012-10-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多