首页 > 解决方案 > 一些管理 Jenkins 链接不起作用 - Nginx 反向代理,Tomcat

问题描述

我在同一个 Windows 2012 R2 操作系统上设置了 2 个不同版本的 Jenkins。Jenkins v1.590 在 Apache Tomcat Web 服务器后面运行,Jenkins 2.164 作为 Windows 服务运行。两个 Jenkins 实例都可以通过 HTTPS 访问。

为了完成这项工作,我将 Nginx 作为反向代理运行,它将所有请求重定向到https://jenkins.company.com/jenkins到 Tomcat 服务器和https://jenkins2.company.com到 Jenkins 2.164 Windows 服务.

除了 Jenkins v1.590 上的异常行为外,一切都运行良好。我遇到的问题是,当我访问Manage Jenkins 下的一些链接时,它们会重定向到 localhost。

以下是可以正常工作的链接:

然后有一些链接不起作用:

和许多其他人。

如果我复制到新窗口并在末尾添加 / ,我仍然可以访问这些链接,例如:https ://jenkins.company.com/jenkins/configureSecurity/工作正常。

我不确定为什么在 Jenkins v1.590 中会出现这些差异。请注意,我最近在安装 Nginx 之前进行了此更改,所有链接都工作正常。

以下是我的配置:

Nginx:

upstream tomcat_server {
    # Tomcat is listening on default 8080 port
    server 127.0.0.1:8080 fail_timeout=0;
}

server {
    listen       443 ssl;
    server_name  jenkins.company.com/jenkins;

    ssl_certificate C:/nginx1.15.12/certs/jenkins/server.crt;
    ssl_certificate_key C:/nginx1.15.12/certs/jenkins/server.key;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto https;
        proxy_redirect off;
        proxy_connect_timeout      240;
        proxy_send_timeout         240;
        proxy_read_timeout         240;
        # note, there is not SSL here! plain HTTP is used
        proxy_pass http://tomcat_server;

    }
}

雄猫配置:

<Connector executor="tomcatThreadPool"
    port="8080" protocol="HTTP/1.1"
    connectionTimeout="20000"
    redirectPort="8443" 
    proxyName="localhost"
    proxyPort="443"
    scheme="https"/>

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

标签: tomcatnginxjenkinsnginx-reverse-proxy

解决方案


好的,我想通了。我不得不将 Tomcat 服务器上的 proxyName 更改为 url。这最终成为解决方案:

<Connector executor="tomcatThreadPool"
           port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" 
           proxyName="jenkins.company.com"
           proxyPort="443"
           scheme="https"/>

推荐阅读