Creating a reverse proxy in IIS

I am trying to set up a reverse proxy through IIS to serve a third party JavaScript file on the first hostname. Ive installed the ARR module in IIS and created a URL rewrite rule, but for some reason it is not taking effect. I've also gone into the ARR module in IIS and ensured that "Enable Proxy" was set under the "Proxy Settings" section.

Essentially I need to answer queries on my domain

http://my.local.com/iojs/dyn_wdp.js

      

so far actually serving the file:

https://third.party.com/latest/dyn_wdp.js

      

My URL rewriting rule looks like this:

<rule name="reverseproxy" stopProcessing="false">
  <match url="^(.*)iojs/(.*)" />
  <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
  <action type="Rewrite" url="https://third.party.com/{R:2}" appendQueryString="false" />
</rule>

      

However, when I pressed

http://my.local.com/iojs/dyn_wdp.js

      

in my browser, I am still getting controller not found exception in asp.net MVC.

Update: I noticed that if I change the action type to redirect (301) it works, but this redirects to the client, which is not what I want. To rewrite it I need to make the JS seem to be served from my server.

Has anyone done similar things before, and if so, what step am I missing?

+3


source to share


2 answers


Not sure if it will change anything, but this is the rule I have used with success.

<rule name="ReverseProxy" enabled="true" stopProcessing="true">
  <match url="^(.*)iojs/(.*)" />                  
  <action type="Rewrite" url="https://third-party.com/{R:2}" appendQueryString="false" logRewrittenUrl="true" />                
</rule>

      

Basically the same as yours.

I call it like this:

http://my.local.com/iojs/latest/dyn_wdp.js

      

this will create the following matches:

  • {R:0} /iojs/latest/dyn_wdp.js

  • {R:1} /iojs/latest/dyn_wdp.js

  • {R:2} latest/dyn_wdp.js

for the rule to successfully rewrite:

https://third-party.com/

+ latest/dyn_wdp.js

> 200 OK

Pay attention to the last one in the url, as if you didn't include it, it will result in a bad rewrite:



https://third-party.com/

+ dyn_wdp.js

> 404 Not Found

I only have one rule on the Site, if you do it in a virtual directory then it won't work as expected.

Also, according to this installation guide: https://blogs.iis.net/erez/new-features-in-arr-application-request-routing-3-0

  • Stop IIS by running net stop was and net stop wmsvc in elevated command window

  • Set url rewrite (v2)

  • Install Web Farm Framework (v1)

  • Install ARR (v3)

  • Install the external cache module (v1)

Make sure you have the external cache module (v1.1 for now) as it was not installed in my case.

The recommended way to install ARR 3.0 is via WebPlatform, but no external cache is installed for me. I had to do it myself, not sure if it worked or not.

Also, not sure if you got a controller exception or not only 404 files but .js shouldn't go through ASP.NET MVC.

After all this and with your Regex, everything worked as planned.

NTN

0


source


I highly recommend using Nodejs on IIS. There NodeJs hooks up an awesome reverse proxy. https://www.npmjs.com/package/awesome-reverse-proxy Once you set up the web than 20 lines of JS code, the rest of the nginx width base is based on.



0


source







All Articles