tomcat - 一些管理 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/configure
- 系统信息:重定向到:https ://jenkins.company.com/jenkins/systemInfo
- 负载统计:重定向到:https ://jenkins.company.com/jenkins/load-statistics
然后有一些链接不起作用:
- 配置全局安全性:重定向到:https://localhost/jenkins/configureSecurity/错误“本地主机拒绝连接”
- 管理插件:重定向到:https://localhost/jenkins/pluginManager/错误“本地主机拒绝连接”
和许多其他人。
如果我复制到新窗口并在末尾添加 / ,我仍然可以访问这些链接,例如: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" />
解决方案
好的,我想通了。我不得不将 Tomcat 服务器上的 proxyName 更改为 url。这最终成为解决方案:
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
proxyName="jenkins.company.com"
proxyPort="443"
scheme="https"/>
推荐阅读
- npm - 通过npm在本地注册命令cli
- entity-framework-core - EF Core 5:必须是可简化节点
- azure - Azure DevOps Starter Wizard 中缺少资源组字段
- php - php 7.4 mongodb dll 文件(1.9.0) 与 windows 10 系统上的 php 8 不兼容
- angular11 - 使用 HttpClient 的 Angular 11 中的 Cors 问题
- javascript - 如何在 react 中使用 formik 创建动态下拉列表?
- php - 创建排行榜
- vue.js - 上下文和凭据的好处
- node.js - 生产环境中的 MongoDB 备份和恢复
- git - 如何使用 android studio 删除我在 gitlab 上的最后一次推送