IIS Server Farm - URL Rewrite

243 Views Asked by At

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.

<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>

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 ..

FailedReqLogFiles

2

There are 2 best solutions below

0
On BEST ANSWER
    <webFarms>
        <webFarm name="alwaysup" enabled="true">
            <server address="alwaysup-blue" enabled="true">
                <applicationRequestRouting hostName="alwaysup-blue" httpPort="8081" />
            </server>
            <server address="alwaysup-green" enabled="true">
                <applicationRequestRouting hostName="alwaysup-green" httpPort="8082" />
            </server>
            <applicationRequestRouting>
                <healthCheck url="http://alwaysup/up.html" responseMatch="up" />
                <loadBalancing />
                <protocol preserveHostHeader="false">
                    <cache enabled="true" validationInterval="00:01:00" />
                </protocol>
            </applicationRequestRouting>
        </webFarm>

Had to add the preserveHostHeader to webfarm section of configuration.

0
On

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.