3
votes

I’m attempting to set up a reverse proxy through IIS to serve a third party JavaScript file on a first party hostname. I’ve installed the ARR module into IIS and created a URL rewrite rule but for some reason it isn’t taking effect. I’ve also gone into the ARR module in IIS and ensured that ‘Enable Proxy’ is set in the ‘server proxy settings’ section.

Essentially I need to respond to requests on my domain

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

yet actually serve the file from:

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

My URL rewrite rule is as follows:

<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 hit

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

in my browser, I’m still getting a controller not found exception in asp.net MVC.

Update: I've noticed that if I change the action type to redirect (301) it works, but this redirects on the client which isn't what I want. Its a rewrite that I need to do such that the JS appears to be served from my server.

Has anyone done this kind of things before, and if so, what step am I missing?

2
This third part domain sitts outside your network completely then?DavidG
Yes, that's right. Its a completely separate network.LDJ
I'm not sure you can use ARR in that way. I would imagine that the rewrite rule is passing the https://third.party.com/... URL to your IIS server which is effectively giving a 404 as it's not responsible for serving that domain.DavidG
I was looking into the same thing as you. Same scenario. Your regular expression made everything work for me tho. Before that it wasn't matching the rule, even if the rule tester said it worked.amd989
May i ask what is the purpose of dyn_wdp.js ?Venky

2 Answers

0
votes

Not sure if it changes anything but this is the rule I 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 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

so that the rule would successfully rewrite to:

https://third-party.com/ + latest/dyn_wdp.js > 200 OK

Take note of latest in the URL, bacause if you don't include it, it would result in a bad rewrite:

https://third-party.com/ + dyn_wdp.js > 404 Not Found

I only have one rule in the Website, if you do this in a Virtual Directory, then it would not work properly.

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

  1. Stop IIS by running the commands net stop was and net stop wmsvc on an elevated command-prompt window

  2. Install URL rewrite (v2)

  3. Install Web Farm Framework (v1)

  4. Install ARR (v3)

  5. Install the External Cache module (v1)

Make sure you have External Cache module (v1.1 as of now), as it wasn't installed in my case.

The recommended way to install ARR 3.0 is through WebPlatform but that didn't install External Cache for me. I had to do it myself, not sure if that worked or not.

Also, not sure if you got controller not found exception or just a 404 but .js files should not go through ASP.NET MVC.

After all of that, and using your Regex everything started to work as planned.

HTH

0
votes

i highly recommend to use Nodejs on IIS. There re NodeJs pluging awesome reverse proxy. https://www.npmjs.com/package/awesome-reverse-proxy Once you set the network than 20 lines of JS code does the rest width nginx base.