IIS proxy using ARR having problems with directory levels

I am working on configuring IIS 7.5 to make a reverse proxy for a subdirectory of my site.

Here is 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 the Linux network module with apache and the django site.

What I want
All requests for / community / qa / * should be redirected to the specified internal IP address.

What will happen
/ community / qa / - gives 404 (on the main IIS server)
/ community / qa / questions / - gives 404 (on the main IIS server)
- BUT -
/ community / qa / questions / ask / Works !!!
/ community / qa / questions / unanswered / Works !!

Thus, it looks like it works for all URLs that are in two subdirectories from the starting point.

It seems strange to me, and I cannot understand it.

Thanks in advance for your help.

+7
source share
1 answer

I am sure that in your case the problem is in setting UrlRoutingModule . If you look at configuring IIS modules in an ordered view, you will see that the UrlRoutingModule is placed higher than the Rewrite and ApplicationRequestRouting modules are placed. This means that if you have Route-setup for ASP.NET MVC in your application. This setting will affect the requests that come to the server, intercepting them and redirecting them to MVC-Route-Handlers, preventing the reverse proxy from doing this work. For example, if you have a general route setting, for example:

 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/ will not work, because it will match the given Url pattern and will be interpreted as:

/ community / qa / ---> Controller = " community ", Action = " OK "

/ community / qa / questions / ---> Controller = " community ", Action = " qa ", Parameter: Id = " questions "

If you do not have such controllers and actions, you will get Http 404 not found.

/community/qa/questions/ask/ and /community/qa/questions/unanswered/ will work because they do not match the UrlRouting pattern on your system.

So a simple solution is to add UrlRouting (when starting the web application) to ignore the rule for your URL in your configuration:

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

All Articles