简体   繁体   English

如何在IIS上配置一个URL重写/代理规则?

[英]How to configure one URL Rewrite/proxy rules on IIS?

Architecture: User --> ARR Server --> LB --> 2 Web Server serving 2 different sites Web Server1 serving -> https://xxxx-green-xxxx-xxxx.net/xxx/xxx?xx=xxxx where green keyword comes in any place in domain name Web Server2 serving -> https://xxxx-yellow-xxxx-xxxx.net/xxx/xxx?xx=xxxx where yellow keyword comes in any place in domain name 架构:用户 - > ARR服务器 - > LB - > 2 Web服务器服务2个不同的站点Web Server1服务 - > https://xxxx-green-xxxx-xxxx.net/xxx/xxx?xx=xxxx其中绿色关键字来自域名Web Server2服务中的任何位置 - > https://xxxx-yellow-xxxx-xxxx.net/xxx/xxx?xx=xxxx其中黄色关键字出现在域名的任何位置

Requirement: Request format: https://xxxx-green-xxxx-xxxx.net/xxx/xxx?xx=xxxx or yellow URL In ARR we need to filter the URL with green and yellow keyword in URL and send it to respective Web Server IP. 要求:请求格式: https ://xxxx-green-xxxx-xxxx.net/xxx/xxx?xx =xxxx或黄色URL在ARR中,我们需要使用URL中的绿色和黄色关键字过滤URL并将其发送到相应的Web服务器IP。

But all my requests are landing to home page only. 但我的所有请求都只登陆主页。 and even i am confused that whether changing the host will work but i need to give IP which is different for each web server in LB 甚至我感到困惑的是,更改主机是否会工作,但我需要为LB中的每个Web服务器提供不同的IP

We have set this Rule and getting below results: 我们设置了此规则并得到以下结果:

                <rule name="Green" enabled="true" stopProcessing="true">
                <match url="(.*xxx.net)(/.*)" />
                <conditions logicalGrouping="MatchAll" 
                 trackAllCaptures="false">
                    <add input="{HTTP_HOST}" pattern="green" />
                </conditions>
                <action type="Rewrite" url="https://xx.xxx.xx.xx/{R:2}" 
                 appendQueryString="true" />
                 </rule> 
                 Where R:2 is --> xxx/xxx?xx=xxxx

As per your question. 根据你的问题。

You need to write Custom rewrite rule for that. 您需要为此编写自定义重写规则。 So first refer this link 所以首先请参考链接

Into link you can handle your requirement and rewrite to other other web server. 进入链接,您可以处理您的要求并重写到其他其他Web服务器。

So please follow all the step and write you logic into 所以请按照所有步骤,写下你的逻辑
Rewrite(string value) method. 重写(字符串值)方法。

Into this method you need to pass your server url from IIS rules and check via condition like below. 在此方法中,您需要从IIS规则传递服务器URL并通过以下条件检查。

 public string Rewrite(string value)
  {
      if(value.Contains("green"))
        {
         return // your rewrite URL here
        }
      else if(value.Contains("yellow"))
        {
         return // your rewrite URL here
        }
    return value;
  }

So it's working as per your requirement. 所以它按照你的要求工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM