加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 使用ARR的IIS反向代理与目录级别有问题

发布时间:2020-12-16 04:18:53 所属栏目:asp.Net 来源:网络整理
导读:我正在设置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}" log
我正在设置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 / Works !!!
/ community / qa / questions / unanswered / Works !!

所以它似乎适用于从起点开始的2个子目录的所有URL.

这对我来说似乎很奇怪,我无法弄明白.

在此先感谢您的帮助.

解决方法

我很确定在你的情况下问题是在UrlRoutingModule设置中.如果您查看Ordered View中的IIS模块设置,您将看到UrlRoutingModule放置得更高,然后放置Rewrite和ApplicationRequestRouting模块.这意味着,如果您的应用程序中有ASP.NET MVC的Route-setup.此设置将影响服务器拦截它们并将它们转发给MVC-Route-Handler的请求,而不允许反向代理执行它的工作.例如,如果您有这样的常见路由设置:
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应用程序启动时)忽略您的网址规则:

routes.IgnoreRoute("community/qa/{*pathInfo}");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读