【问题标题】:Reverse Proxy with ARR using Azure platform使用 Azure 平台的 ARR 反向代理
【发布时间】:2015-07-16 09:42:48
【问题描述】:

我有一个类似 example.com 的域,并且我还有一个托管在 Azure 中的网站,例如名为 mysite1.azurewebsites.net。

现在来自 live.example.com 的所有流量都转到 mysite1.azurewebsites.net。我们将自定义域名指向我们的 Windows Azure 网站。我想使用反向代理技术将一些请求(例如来自客户端 A 的请求)重定向到 mysite2.azurewebsites.net,而其他客户端的其他请求仍然转到 mysite1.azurewebsites.net。所有这些都应该在他们登录后发生。 (live.example.com 是一个登录页面)

Client A         live.example.com  ======> mysite2.azurewebsites.net
Client B         live.example.com  ======> mysite3.azurewebsites.net
Client C         live.example.com  ======> mysite4.azurewebsites.net
Other Clients    live.example.com  ======> mysite1.azurewebsites.net

这是否可以使用带有 ARR 的反向代理来实现?如果是,怎么做?

谢谢

【问题讨论】:

    标签: azure iis reverse-proxy azure-web-app-service arr


    【解决方案1】:

    这篇博文解释了如何做到这一点http://ruslany.net/2014/05/using-azure-web-site-as-a-reverse-proxy/

    总而言之,在live.example.com 上,您需要设置一个看起来像这样的 xdt 变换

    <?xml version="1.0"?>  
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">  
      <system.webServer>  
        <proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="false"  reverseRewriteHostInResponseHeaders="false" />  
      </system.webServer>  
    </configuration>
    

    然后您需要设置一个 URL 重写规则来执行您想要的映射。例如,如果您打算使用 UserAgent 来告诉您客户端名称,那么它将是这样的

    <configuration>  
      <system.webServer>  
        <rewrite>  
          <rules>  
            <rule name="ClientA">
              <match url="^(.*)$" />
                <conditions>
                  <add input="{HTTP_USER_AGENT}" pattern="Client A" />
                </conditions>
              <action type="Rewrite" url="https://mysite2.azurewebsites.net/{R:1}" />
            </rule>
            <rule name="ClientB">
              <match url="^(.*)$" />
                <conditions>
                  <add input="{HTTP_USER_AGENT}" pattern="Client B" />
                </conditions>
              <action type="Rewrite" url="https://mysite3.azurewebsites.net/{R:1}" />
            </rule>
            <rule name="ClientC">
              <match url="^(.*)$" />
                <conditions>
                  <add input="{HTTP_USER_AGENT}" pattern="Client C" />
                </conditions>
              <action type="Rewrite" url="https://mysite4.azurewebsites.net/{R:1}" />
            </rule>
            <rule name="Others" stopProcessing="true">
              <match url="^(.*)$" />
              <action type="Rewrite" url="https://mysite1.azurewebsites.net/{R:1}" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>
    

    【讨论】:

    • 感谢您发布此答案。我需要一些时间来实现它。我会回来更新的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    • 1970-01-01
    • 2022-12-29
    • 2015-09-04
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多