Search code examples
iisproxyarr

How to configure IIS ARR to do a ProxyPass?


Problem:

Need to proxy pass requests that ONLY matches the pattern: mywebsite.com/two-letter-country-code e.g mywebsite.com/es/ to mywebsite.vendor.com/es this second url is a Third-party vendor that will return content translated.

Work In progress:

IIS doesn't natively support ProxyPass so I installed "Application Request Routing (ARR)" to configure a forward proxy following the instructions in this article https://www.iis.net/learn/extensions/configuring-application-request-routing-arr/creating-a-forward-proxy-using-application-request-routing, in the step 14 while configuring the rewrite rule it says to add:

Rewrite URL: http://{C:1}/{R:0}

If my understand is correct in my case I will want to do something like

Rewrite URL: http://mywebsite.sl.vendor.com/{C:#}

Where {C:#} will return "es" or whatever the language the URL is going to.

My questions

1. Is my rewrite understanding correct?

2. Do I have to configure the Server Farms?

I noticed that by installing ARR, "Server Farm" is now available for configuration, but not sure if there is anything I need to do there.


Solution

  • 1. Is my rewrite understanding correct?

    No, since I wanted to match the two letter country codes the Patter should be:

    ^([a-z]{2}/(.*)|/[a-z]{2}$)
    

    And the Rewrite URL under Action Properties should be:

    https://mywebsite.sl.vendor.com/{R:0}
    

    {R:0} will be the back-reference of specified pattern so an incoming request for mywebsite.com/es/ will be proxy passed as mywebsite.vendor.com/es were {R:0}=es/ as expected

    2. Do I have to configure the Server Farms?

    Is not require to do any special configuration in the server Farms to get the forward proxy working.

    The third party service I was forwarding the request to, require to have the host header to be the server forwarding the request in this case mywebsite.com but in their end they were receiving mywebsite.vendor.com, to accomplish this you have to set the property preserveHostHeader to true, this can be found in the Configuration Editor