IIS 10 - HTTP 到 HTTPS 重定向然后路由到服务器场 (ARR) - 重定向次数过多

IIS 10 - HTTP 到 HTTPS 重定向然后路由到服务器场 (ARR) - 重定向次数过多

我服务器上某个网站的 web.config 中有一条 URL 重写规则。但我们正在实施一个服务器场,将多个网站放在同一个物理服务器上,以启用“热插拔”部署,如下所述这里

我发现此链接,这似乎应该可以工作,因为它首先重定向,所以它不应该触及重写规则……然后,当请求作为 HTTPS 请求返回时,第一条规则将被绕过,场重写应该得到执行。但我得到了可怕的错误ERR_TOO_MANY_REDIRECTS

我尝试将重写规则从 web.config 移至applicationHost.conf,但出现同样的错误。

我错过了什么?

第二个问题:web.config 是否优先于 applicationHost.config 规则?

Web.congif重写规则:

<rewrite>
  <rules>
    <rule name="Redirect to HTTPS" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
    </rule>
  </rules>
</rewrite>

applicationHost.config 重写规则:

<rule name="Route https test to server farm" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="test.com" />
        <add input="{SERVER_PORT}" pattern="443" />
        <add input="{HTTPS}" pattern="ON" />
        <add input="{SERVER_PORT}" pattern="^(800.*)$" negate="true" />
    </conditions>
    <action type="Rewrite" url="http://test-farm/{R:0}" />
</rule>

然后将 web.config 规则移至 applicationHost.config

<rule name="Redirect to HTTPS" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="test.com" />
        <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>

<rule name="Route https test.com to server farm" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="test.com" />
        <add input="{SERVER_PORT}" pattern="443" />
        <add input="{HTTPS}" pattern="ON" />
        <add input="{SERVER_PORT}" pattern="^(800.*)$" negate="true" />
    </conditions>
    <action type="Rewrite" url="http://test-farm/{R:0}" />
    </rule>
</globalRules>

网站绑定规则:

<site name="test-Prod-A" id="11" serverAutoStart="true">
    <application path="/" applicationPool="test-Prod-A">
        <virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\test-Prod-A\website" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:8001:" />
<binding protocol="https" bindingInformation="*:8002:" />
    </bindings>
</site>
<site name="test-Prod-B" id="12" serverAutoStart="true">
    <application path="/" applicationPool="test-Prod-B">
        <virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\test-Prod-B\website" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:8003:" />
        <binding protocol="https" bindingInformation="*:8004:" />
    </bindings>
</site>
<site name="test-Prod-Farm" id="13">
    <application path="/">
        <virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot" />
    </application>
    <bindings>
        <binding protocol="https" bindingInformation="*:443:test.com" sslFlags="1" />
        <binding protocol="http" bindingInformation="*:80:test.com" />
    </bindings>
</site>

农场绑定:

<webFarms>
    <webFarm name="test-farm" enabled="true">
        <server address="test-a" enabled="true">
            <applicationRequestRouting httpPort="8001" httpsPort="8002" />
        </server>
        <server address="test-b" enabled="true">
            <applicationRequestRouting httpPort="8003" httpsPort="8004" />
        </server>
    </webFarm>
</webFarms>

相关内容