gpt4 book ai didi

asp.net - 使用 ARR 的 IIS 反向代理存在目录级别问题

转载 作者:行者123 更新时间:2023-12-04 10:21:12 24 4
gpt4 key购买 nike

我正在设置 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设置。如果您在有序 View 中查看 IIS 模块设置,您将看到 UrlRoutingModule高于 RewriteApplicationRequestRouting放置模块。这意味着,如果您的应用程序中有 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 模式并被解释为:

/ 社区 / 质量保证 / ---> Controller =" 社区 ", 行动=" qa "

/ 社区 / 质量保证 / 问题 / ---> Controller =“ 社区”,操作=“ qa”,参数:id=“ 问题

如果你没有这样的 Controller 和 Action ,你会得到 Http 404 未找到。
/community/qa/questions/ask//community/qa/questions/unanswered/会起作用,因为它们与您系统中的任何 UrlRouting 模式都不匹配。

如此简单的解决方案是添加您的 UrlRouting 配置(当 Web 应用程序启动时)忽略您的 url 规则:
routes.IgnoreRoute("community/qa/{*pathInfo}");

关于asp.net - 使用 ARR 的 IIS 反向代理存在目录级别问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5547419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com