使用 ARR 的 IIS 反向代理存在目录级别问题
我正在设置 IIS 7.5 来为我的网站的子目录进行反向代理。
这是 web.config url 重写:
<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。
这对我来说似乎很奇怪,我无法弄清楚。
预先感谢您的任何帮助。
I am working on setting up IIS 7.5 to do reverse proxy for a subdirectory of my site.
Here is the 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>
The ip address points to a networked linux box with apache and a django site.
What I want
All request for /community/qa/* to be redirected to the internal IP specified.
What happens
/community/qa/ - gives 404 (on main IIS server)
/community/qa/questions/ - gives 404 (on main IIS server)
- BUT -
/community/qa/questions/ask/ Works!!!
/community/qa/questions/unanswered/ Works!!
So it seems that it works for all URLs that are 2 subdirectories deep from the starting point.
This just seems odd to me, and I can not figure it out.
Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定在您的情况下问题出在
UrlRoutingModule
设置中。如果您在有序视图中查看 IIS 模块设置,您会发现UrlRoutingModule
的位置高于Rewrite
和ApplicationRequestRouting
模块的位置。这意味着如果您的应用程序中有 ASP.NET MVC 的路由设置。此设置将影响到达服务器的请求,拦截它们并将它们转发到 MVC-Route-Handlers,不允许反向代理完成它的工作。例如,如果您有这样的常见路由设置:在您的情况下
/community/qa/
和/community/qa/questions/
将不起作用,因为它会匹配给定的网址模式,将被解释为:/community/ qa/ ---> Controller="community ", Action="qa"
/社区/ qa/ 问题/ ---> Controller="community", Action="qa", Parameter: Id="questions"
如果您没有这样的控制器您将收到 Http 404 Not Found 的操作。
/community/qa/questions/ask/
和/community/qa/questions/unanswered/
可以使用,因为它们与系统中的任何 UrlRouting 模式都不匹配。所以简单的解决方案是在你的 UrlRouting 配置中添加(当 Web 应用程序启动时)忽略你的 url 规则:
I'm quite sure that in your case problem is in
UrlRoutingModule
setup. If you look at IIS Modules Setup in Ordered View you will see thatUrlRoutingModule
is placed higher thenRewrite
andApplicationRequestRouting
modules are placed. That means that if you have in your application Route-setup for ASP.NET MVC. This setup will influence requests that come to server intercepting them and forwarding them to MVC-Route-Handlers, not allowing reverse-proxy to do it's job. For example if you have common route setup like this:In your case
/community/qa/
and/community/qa/questions/
wouldn't work because it would match given Url pattern and would been interpreted as:/community/ qa/ ---> Controller="community", Action="qa"
/community/ qa/ questions/ ---> Controller="community", Action="qa", Parameter: Id="questions"
If you have no such controllers and actions you will get Http 404 Not Found.
/community/qa/questions/ask/
and/community/qa/questions/unanswered/
would work, because they don't match any UrlRouting pattern in your system.So simple solution is to add in your UrlRouting configuration (when Web Application starts) ignore rule for your url: