Asp.net

IIS AAR - 反向代理的 URL 重寫 - 如何發送 HTTP_HOST

  • February 12, 2013

嘗試在多個後端 IIS 伺服器前使用 AAR 作為反向代理。

  • 分配給執行 IIS/AAR 的伺服器的一個公共 IP 地址
  • 然後設置出站 URL 重寫規則以根據主機名重定向到多個後端伺服器之一。

有點工作,但總是返回後端伺服器預設站點(不是映射到主機名的站點),因此看起來主機名(HTTP_HOST)沒有從代理伺服器傳遞到後端伺服器。

(我已經通過編輯主機驗證繞過反向代理,後端伺服器返回綁定到主機頭的正確站點)

這是一個規則範例(192.168.0.99 是內部伺服器,site.myco.com 是主機名)

   <rewrite>
       <rules>
           <rule name="ReverseProxyInboundRule1" stopProcessing="true">
               <match url="(.*)" />
               <action type="Rewrite" url="http://192.168.1.99/{R:1}" />                   
           </rule>
       </rules>
   </rewrite>

嘗試過放置伺服器變數

   <!-- Guessing server.myco.com is hard coded -->
   <serverVariables>
       <set name="HTTP_HOST" value="server.myco.com" />
   </serverVariables>

   <!-- Guessing picked up dynamically from incoming request host header -->
   <serverVariables>
       <set name="HTTP_HOST" value="{HTTP_HOST}" />
   </serverVariables>

但唉總是返回預設綁定 - 有什麼想法嗎?

這篇文章有答案 - Modifying headers with IIS7 Application Request Routing

需要啟用 preserveHostHeader - 在 UI 中看不到你是如何做到的,但這有效

從命令行執行它以更新 Machine/webroot/apphost 配置

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

引用自:https://stackoverflow.com/questions/14841986