【发布时间】:2018-09-06 16:03:53
【问题描述】:
我的情况如下:
我们在单个服务器上拥有一系列 CI 服务,例如 TeamCity、YouTrack 和 OctopusDeploy。目前,我们通过 DNS 名称加端口访问所有这些,例如:
TeamCity: http://server.company.com
YouTrack: http://server.company.com:1234
OctopusDeploy: http://server.company.com:5678/octopus
我目前正在调整它,以便我们可以通过 https 访问这些服务。为此,我通过使用 IIS URL 重写来处理 SSL 身份验证,将 IIS 服务器设置为反向代理。这已经有效,我现在可以通过 https://server.company.com 访问 TeamCity
但是,在我做这件事的同时,我还想使用 IIS URL Rewrite 来美化地址,并摆脱记住端口号的需要。我想要实现的是以下重定向:
https://server.company.com -> http://server.company.com (already working)
https://server.company.com/youtrack -> http://server.company.com:1234
https://server.company.com/octopus -> http://server.company.com:5678/octopus
我已经尝试添加以下规则:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="ReverseProxyInboundRule2" stopProcessing="true">
<match url="^(https://server.company.com/youtrack)(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://server.company.com:1234/{R:2}" />
</rule>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{PATH}" pattern="youtrack" negate="true" />
</conditions>
<action type="Rewrite" url="http://server.company.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
...并在 IIS 管理器中对其进行了测试,它正确识别规则和条件,并返回正确的反向规则。
但是,当我尝试访问 https://server.company.com/youtrack 时,我被重定向到 http://server.company.com/youtrack 而不是我想要的 http://server.company.com:1234。这就像 ReverseProxyInboundRule2 根本没有评估。
我确信对此有一个合乎逻辑的解释,并有一种方法可以使它发挥作用。我一个人看不到。我可以做些什么来完成这项工作?
2018 年 3 月 30 日更新:
好的,所以我想出了一个部分有效的配置。如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Reverse Proxy to TeamCity" stopProcessing="true">
<match url="^teamcity/(.*)" />
<action type="Rewrite" url="http://server.company.com/{R:1}" />
</rule>
<rule name="Reverse Proxy to YouTrack" stopProcessing="true">
<match url="^youtrack/(.*)" />
<action type="Rewrite" url="http://server.company.com:1234/issues/{R:1}" />
</rule>
<rule name="Reverse Proxy to Hub" stopProcessing="true">
<match url="^hub/(.*)" />
<action type="Rewrite" url="http://server.company.com.de:5678/hub/{R:1}" />
</rule>
<rule name="Reverse Proxy to UpSource" stopProcessing="true">
<match url="^upsource/(.*)" />
<action type="Rewrite" url="http://server.company.com.de:9876/{R:1}" />
</rule>
<rule name="Reverse Proxy to Octopus" stopProcessing="true">
<match url="^octopus/(.*)" />
<action type="Rewrite" url="http://server.company.com:5432/octopus/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
此配置将请求重定向如下:
https://server.company.com -> http://server.company.com
https://server.company.com/youtrack -> http://server.company.com:1234/issues/
https://server.company.com/hub -> http://server.company.com:5678/hub/
https://server.company.com/upsource -> http://server.company.com:9876
https://server.company.com/octopus -> http://server.company.com:5432/octopus/
这非常适合八达通。
在 Hub 上,地址旁边有一个“连接不安全”通知,说“网站的某些部分(例如图像)不安全”。进入页面信息,它在“技术细节”下的“安全”选项卡中表示,连接只是部分加密的。但是,页面的其余部分似乎工作正常。
TeamCity 和 YouTrack 更异想天开。在 Chrome 上,TeamCity 可以正常工作(一段时间后,它会随机断开连接),但 YouTrack 会出现 404 错误,而在 Firefox 上,TeamCity 和 YouTrack 都以无法使用的“纯文本”形式显示。
与此同时,UpSource 在任一浏览器上都提供一个空白页面。
我已经在各种浏览器和机器上对此进行了交叉测试,得出的结论是,如果我已经在这些服务器上登录到这些服务的 http 版本,TeamCity、YouTrack 和 Hub 只能“有点”工作。如果我没有登录,那么我会收到 TeamCity 和 YouTrack 的 404 错误。至于 Hub,我在尝试使用“不支持 POST 方法”消息登录时收到 405 错误。
所以我上面写的配置的基本结果如下:
TeamCity: 404 Error
YouTrack: 404 Error
Hub: 405 Error on login
UpSource: Blank Page
Octopus: Working
【问题讨论】:
标签: iis url-rewriting reverse-proxy