Score:0

IIS Reverse Proxy with same hostheader under condition on 2 internal frontend server

bt flag

a reverse proxy should be simple i thought but i encountered a problem. i try to accomplish the following: ive 2 webfrontends (serverA, ServerB) which hosting a webapplication contoso.local. then ive a server which is a reverse proxy on iis (with ARR & URL Rewrite)

the reverse proxy should send all incoming requests of contoso.local to serverA

if path123 is in the url it should send the request to serverB

i need to preserve the hostheader

so i configured the following on the reverse proxy:

  • enabled the proxy in ARR

  • set preservehostheader via system.webServer/proxy"%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/proxy -preserveHostHeader:true /commit:apphost

  • added a new website in iss which has contoso.local as hostheader

  • added 2 rules with the following config described in web.config of that website contoso.local:

         <rewrite>
         <outboundRules>
             <preConditions>
                 <preCondition name="ResponseIsHtml1">
                     <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                 </preCondition>
             </preConditions>
         </outboundRules>
         <rules>
             <clear />
             <rule name="ReverseProxyInboundRule2" stopProcessing="true">
                 <match url="^path123(.*)" />
                 <conditions>
                     <add input="{CACHE_URL}" pattern="^(https?)://" />
                 </conditions>
                 <action type="Rewrite" url="{C:1}://serverB/{R:1}" />
             </rule>
             <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                 <match url="(.*)" />
                 <conditions>
                     <add input="{CACHE_URL}" pattern="^(https?)://" />
                 </conditions>
                 <action type="Rewrite" url="{C:1}://serverA/{R:1}" />
             </rule>
    
         </rules>
     </rewrite>
    

now if i test, ill get to serverA always. am i missing anything or is there any wrong in my logic?

Lex Li avatar
vn flag
Enable FRT https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules and you can see for yourself.
danielW avatar
bt flag
sadly there is no option for "rewrite" as tracing provider
danielW avatar
bt flag
ok, repaired the rewrite module installation and then it pops up
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.