【问题标题】:IIS Reverse Proxy Outbound RulesIIS 反向代理出站规则
【发布时间】:2020-04-27 09:54:34
【问题描述】:

我正在尝试设置已经在 Linux 中使用 nginx 实现的反向代理。我正在使用 URL 重定向插件和 ARR。我想要做的是当有人击中

www.example.com/product1/ 

它应该将请求发送给

product1.example.com:8443. 

如果有人打了

www.example.com/product2/ 

它应该将请求发送到 product2.example.com:8449 等等等等。 我面临的问题是,当请求到达product1.example.com:8443 使用www.example.com/product1/ 并打开内容页面时,每当我尝试使用www.example.com/product1/ 访问product1.example.com:8443 的内容时,它都会给我错误404.0 - 未找到,请请注意,product1.example.com:8443 和 product2.example.com:8449 未托管在 IIS 上。这些在不同的虚拟机上。我只是使用 IIS 反向代理来重写 URL。 我的理解是任何相对路径,或者就此而言,绝对路径也需要转换为新的 URL 结构。

原网页,conf文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="^product1(.*)" />
<action type="Rewrite" url="http://product1.example.com:8443/{R:1}" />
</rule>
<rule name="Portainer-reverse-proxy" stopProcessing="true">
<match url="^product2(.*)" />
<action type="Rewrite" url="http://product2.example.com:8449/{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^/(.*)" />
<action type="Rewrite" value="/{C:1}/{R:1}" />
<conditions>
<add input="{URL}" pattern="^(product1|product2).*" />
</conditions>
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>

【问题讨论】:

    标签: xml iis reverse-proxy


    【解决方案1】:

    你的rewrite url不正确,你可以试试下面的代码:

    <rule name="ReverseProxyInboundRule1" stopProcessing="true">
    <match url="^product1(.*)" />
    <action type="Rewrite" url="http://product1.example.com:8443{R:1}" />
    </rule>
    <rule name="Portainer-reverse-proxy" stopProcessing="true">
    <match url="^product2(.*)" />
    <action type="Rewrite" url="http://product2.example.com:8449{R:1}" />
    </rule>
    

    最好的问候,

    山姆

    【讨论】:

    • 我看到你在product1.example.com:8443{R:1} 前面添加了 http:// 我省略了 http 因为 StackOverflow 不允许在问题中发布超过 10 个链接。不知何故我在问题中添加了 Http再次并在规则中使用同样的方法。问题依旧。
    • 去掉url中端口后面的“/”,你试过吗?
    猜你喜欢
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    • 2018-07-23
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    • 1970-01-01
    相关资源
    最近更新 更多