使用 ARR 的 IIS 反向代理存在目錄級別問題
我正在設置 IIS 7.5 為我的站點的子目錄做反向代理。
這是 web.config url-rewrite:
<clear /> <rule name="Reverse Proxy to Community" stopProcessing="true"> <match url="^community/qa/(.*)" /> <action type="Rewrite" url="http://xxx.xxx.xxx.xxx/{R:1}" logRewrittenUrl="true" /> </rule>ip 地址指向一個帶有 apache 和 django 站點的聯網 linux 機器。
我想要什麼
將 /community/qa/* 的所有請求重定向到指定的內部 IP。
會發生什麼
/community/qa/ - 給出 404(在主 IIS 伺服器上)
/community/qa/questions/ - 給出 404(在主 IIS 伺服器上)
- 但是 -
/community/qa/questions/ask/ 有效!!!
/community/qa/questions/unanswered/ 有效!!
因此,它似乎適用於從起點深 2 個子目錄的所有 URL。
這對我來說似乎很奇怪,我無法弄清楚。
提前感謝您的幫助。
我很確定在您的情況下問題出在
UrlRoutingModule設置中。如果您在 Ordered View 中查看 IIS 模組設置,您會看到它UrlRoutingModule被放置得更高,Rewrite並且ApplicationRequestRouting模組被放置。這意味著,如果您的應用程序中有 ASP.NET MVC 的路由設置。此設置將影響到達伺服器的請求,攔截它們並將它們轉發到 MVC-Route-Handlers,不允許反向代理完成它的工作。例如,如果您有這樣的常見路由設置:routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults );在您的情況下
/community/qa/,/community/qa/questions/它不起作用,因為它會匹配給定的 Url 模式並被解釋為:/ community / qa / —> Controller=" community “,Action=” qa "
/ community / qa / questions / —> Controller=" community “,Action=” qa “,參數:Id=” questions "
如果您沒有此類控制器和操作,您將獲得 Http 404 Not Found。
/community/qa/questions/ask/並且/community/qa/questions/unanswered/會起作用,因為它們與您系統中的任何 UrlRouting 模式都不匹配。如此簡單的解決方案是添加您的 UrlRouting 配置(當 Web 應用程序啟動時)忽略您的 url 規則:
routes.IgnoreRoute("community/qa/{*pathInfo}");