Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS Reverse Proxy using ARR having problems with directory levels

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.

like image 374
Shaleen Avatar asked Apr 05 '11 05:04

Shaleen


1 Answers

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 that UrlRoutingModule is placed higher then Rewrite and ApplicationRequestRouting 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:

routes.MapRoute(
  "Default", // Route name
  "{controller}/{action}/{id}", // URL with parameters
  new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

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:

routes.IgnoreRoute("community/qa/{*pathInfo}");
like image 115
Dao Avatar answered Nov 14 '22 13:11

Dao