IIS服务器群 – URL重写

huangapple go评论62阅读模式
英文:

IIS Server Farm - URL Rewrite

问题

我正在尝试创建一个IIS服务器群集,并且在使URL重写正常工作方面遇到了问题。

Windows 10企业版
IIS 10

以下是相关的配置。

<applicationPools>
    <add name="always-blue" autoStart="true">
        <processModel pingingEnabled="true" pingResponseTime="00:01:30" />
    </add>
    <add name="always-green" autoStart="true">
        <processModel pingingEnabled="true" pingResponseTime="00:01:30" />
    </add>
</applicationPools>
<sites>
    <site name="always-blue" id="2" serverAutoStart="true">
        <application path="/" applicationPool="always-blue">
            <virtualDirectory path="/" physicalPath="C:\xxx\always-up-blue" />
        </application>
        <bindings>
            <binding protocol="http" bindingInformation="*:80:alwaysup-blue" />
        </bindings>
    </site>
    <site name="always-green" id="3" serverAutoStart="true">
        <application path="/" applicationPool="always-green">
            <virtualDirectory path="/" physicalPath="C:\xxx\always-up-green" />
        </application>
        <bindings>
            <binding protocol="http" bindingInformation="*:80:alwaysup-green" />
        </bindings>
    </site>
</sites>
<rewrite>
    <globalRules>
        <rule name="alwaysup rewrite" stopProcessing="false">
            <match url=".*" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^alwaysup$" />
                <add input="{SERVER_PORT}" pattern="^80$" />
            </conditions>
            <action type="Rewrite" url="http://alwaysup/{R:0}" />
        </rule>
    </globalRules>
</rewrite>

http://alwaysup-blue 和 http://always-green 网站都正常运行。然而,服务器群集不起作用。http://alwaysup 返回502错误。我检查了带有FailTracedURLs的日志,但无法理解其中的内容。以下是日志链接:

IIS服务器群 – URL重写

英文:

I am trying to create IIS Server Farm, and having issues with the URL Rewrite to work correctly.

Windows 10 Enterprise
IIS 10

Below is the relevant configurations.

&lt;applicationPools&gt;
    &lt;add name=&quot;always-blue&quot; autoStart=&quot;true&quot;&gt;
        &lt;processModel pingingEnabled=&quot;true&quot; pingResponseTime=&quot;00:01:30&quot; /&gt;
    &lt;/add&gt;
    &lt;add name=&quot;always-green&quot; autoStart=&quot;true&quot;&gt;
        &lt;processModel pingingEnabled=&quot;true&quot; pingResponseTime=&quot;00:01:30&quot; /&gt;
    &lt;/add&gt;
&lt;/applicationPools&gt;
&lt;sites&gt;
    &lt;site name=&quot;always-blue&quot; id=&quot;2&quot; serverAutoStart=&quot;true&quot;&gt;
        &lt;application path=&quot;/&quot; applicationPool=&quot;always-blue&quot;&gt;
            &lt;virtualDirectory path=&quot;/&quot; physicalPath=&quot;C:\xxx\always-up-blue&quot; /&gt;
        &lt;/application&gt;
        &lt;bindings&gt;
            &lt;binding protocol=&quot;http&quot; bindingInformation=&quot;*:80:alwaysup-blue&quot; /&gt;
        &lt;/bindings&gt;
    &lt;/site&gt;
    &lt;site name=&quot;always-green&quot; id=&quot;3&quot; serverAutoStart=&quot;true&quot;&gt;
        &lt;application path=&quot;/&quot; applicationPool=&quot;always-green&quot;&gt;
            &lt;virtualDirectory path=&quot;/&quot; physicalPath=&quot;C:\xxx\always-up-green&quot; /&gt;
        &lt;/application&gt;
        &lt;bindings&gt;
            &lt;binding protocol=&quot;http&quot; bindingInformation=&quot;*:80:alwaysup-green&quot; /&gt;
        &lt;/bindings&gt;
    &lt;/site&gt;
&lt;/sites&gt;

&lt;rewrite&gt;
    &lt;globalRules&gt;
        &lt;rule name=&quot;alwaysup rewrite&quot; stopProcessing=&quot;false&quot;&gt;
            &lt;match url=&quot;.*&quot; /&gt;
            &lt;conditions&gt;
                &lt;add input=&quot;{HTTP_HOST}&quot; pattern=&quot;^alwaysup$&quot; /&gt;
                &lt;add input=&quot;{SERVER_PORT}&quot; pattern=&quot;^80$&quot; /&gt;
            &lt;/conditions&gt;
            &lt;action type=&quot;Rewrite&quot; url=&quot;http://alwaysup/{R:0}&quot; /&gt;
        &lt;/rule&gt;
    &lt;/globalRules&gt;
&lt;/rewrite&gt;

Both http://alwaysup-blue and http://always-green websites are up and work normal. However the server farm doesn't work. http://alwaysup -> Returns 502. I checked the logs with FailTracedURLs, but couldn't make much sense of that. Here are the logs ..

IIS服务器群 – URL重写

答案1

得分: 0

跟踪警告: REWRITE_DISABLED_KERNEL_CACHE

这个警告表示:如果一个重写规则集使用了列表中未提及的任何服务器变量,那么该规则集被认为对输出缓存是不安全的。这意味着URL重写模块将禁用内核模式缓存,无论请求的URL是否被重写。参考:与IIS输出缓存的交互

但我认为这个警告并不是502错误的根本原因,问题应该出在你的部署过程中。我按照教程在IIS中使用了蓝绿部署,没有发生错误。你可以尝试按照此链接中的步骤重新部署:如何在IIS中使用蓝绿部署

英文:

> trace warning: REWRITE_DISABLED_KERNEL_CACHE

This warning indicates: if a rewrite rule set uses any server variable not mentioned in the list, the rule set is considered unsafe for output caching. This means that the URL Rewrite Module will disable kernel mode caching for all requests whether the request URLs were rewritten or not. Refer to: Interaction with IIS Output Caching

But I don't think this warning is the root cause of 502 error, the problem should be in your deployment process. I followed the tutorial to use blue-green deployment in IIS and no error occurred. You can try redeploying by following the steps in this link: How to use Blue-Green Deployment in IIS.

答案2

得分: 0













在配置的webfarm部分中添加了preserveHostHeader。

英文:
    &lt;webFarms&gt;
        &lt;webFarm name=&quot;alwaysup&quot; enabled=&quot;true&quot;&gt;
            &lt;server address=&quot;alwaysup-blue&quot; enabled=&quot;true&quot;&gt;
                &lt;applicationRequestRouting hostName=&quot;alwaysup-blue&quot; httpPort=&quot;8081&quot; /&gt;
            &lt;/server&gt;
            &lt;server address=&quot;alwaysup-green&quot; enabled=&quot;true&quot;&gt;
                &lt;applicationRequestRouting hostName=&quot;alwaysup-green&quot; httpPort=&quot;8082&quot; /&gt;
            &lt;/server&gt;
            &lt;applicationRequestRouting&gt;
                &lt;healthCheck url=&quot;http://alwaysup/up.html&quot; responseMatch=&quot;up&quot; /&gt;
                &lt;loadBalancing /&gt;
                &lt;protocol preserveHostHeader=&quot;false&quot;&gt;
                    &lt;cache enabled=&quot;true&quot; validationInterval=&quot;00:01:00&quot; /&gt;
                &lt;/protocol&gt;
            &lt;/applicationRequestRouting&gt;
        &lt;/webFarm&gt;

Had to add the preserveHostHeader to webfarm section of configuration.

huangapple
  • 本文由 发表于 2023年7月31日 21:25:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76804095.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定