詹金斯在nginx后面没有子目录

时间:2014-02-04 16:46:41

标签: nginx url-rewriting jenkins reverse-proxy

我让Jenkins在我的Glassfish安装中运行,所以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;
    }
}

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

3 个答案:

答案 0 :(得分:1)

然后改变:

proxy_pass http://localhost:8090;

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

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

答案 1 :(得分:1)

在我看来,问题是Glassfish配置。

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

<context-root/>

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

SO上似乎有similar questions

答案 2 :(得分:0)

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