Reverse proxy virtual directory to Nodejs site using arr (Application Request Routing) in IIS7

Source: Internet
Author: User

Reverse proxy virtual directory to Nodejs site using arr (Application Request Routing) in IIS7

Goal:

1. Visit Www.arrdemo.com/proxy jump to localhost:8898 's Nodejs site

Pages of the 2.Nodejs site can be returned to the browser, including JS,CSS, pictures

3.Nodejs site Res.redirect (") redirect to correct, including in-station jumps and off-site jumps

Step: 1. Create a new site-bound domain name www.arrdemo.com, configure the host file to point to this machine, and create a new virtual directory proxy.

Note Remove the check in front of "Enable dynamic content Compression" and "Enable static content compression", such as compression, virtual directory. Otherwise, the following error will occur:

HTTP error 500.52-url Rewrite Module Error. Outbound rewrite rules cannot be applied when the content of the HTTP response is encoded ("gzip").
2. Start the Nodejs site http://localhost:8898

This site is a microblog instance of the Nodejs Development Guide, which was changed to a Express4.13.1 version during the learning process.

3. Install ARR, enable Proxy

(http://www.iis.net/downloads/microsoft/application-request-routing)

After the installation is complete, open iis-> Check server name, double-click the application Request Routing under the IIS node under the function view, click on the right operation view under the proxy node of the server proxy settings-> Tick the check box on the front of the Enable proxy

4. Configure URL rewrite rules for virtual directories

In the IIS node, the site node, the virtual directory node can be configured with URL re-rules, and first-level inheritance. After the configuration is complete, the information is saved to the corresponding Web. config file. So if www.arrdemo.com is deployed on multiple servers, each server's proxy virtual directory needs to be redirected when it can take a quick deployment of the Web. config file under the copy proxy. This is only deployed under the proxy virtual directory, excluding the effect of inheritance.

First, configure the inbound rules. rewrite URLs such as Http://www.arrdemo.com/proxy/reg to Http://localhost:8898/reg

Double-click URL rewrite to select the blank rule template from the inbound rule. The rest of the attention to the picture notes:

To this step normally in the browser input http://www.arrdemo.com/proxy, you should be able to see the content output, but there is no style and JS effect. Such as:

This is because inbound rules can forward requests to Nodejs, and Nodejs the returned HTML content to the browser. But the HTML CSS and JS and the path of the picture is generally relative to the site root path, will not be added to the virtual directory proxy, so the front-end can not see any style.

At this time the outbound rules to play ....

And then , configure outbound rules. put http://localhost:8898/bootstrap/. Such URLs are converted into http://www.arrdemo.com/proxy/bootstrap/ .....

I'll show you the rules that have been configured here. Rules are more in order, and it is important to match whether or not to "stop processing." For example: match the two re-type rules, then will appear in the output proxy/proxy situation, resulting in an error.

The first rule bbbb, processing output js, CSS, pictures and other paths are not the problem.

After finishing the first rule, it should be all but drinking. However.... However..... Open the page after landing to jump to the first page of the address into a www.arrdemo.com did not add proxy. Then the next rule goes ...

The second rule deals with Res.redirect ('/'); This kind of station jumps

Station jump need to add Proxy in the output, mainly check {response_status} variable is 302, and then output/proxy{r:1} When overridden, the rule is as follows (please look at the picture):

In this way after the station jump, there is no problem.

A third rule deals with Res.redirect (' http://www.baidu.com '); This off-site jump

The difference from the second rule is that this jump does nothing and throws directly, with the following rules:

Now go to the browser to visit and try it, if not yet, please restart the site.

Summarize:

1. Complete configuration file to serve

Web. config under proxy

2. Find information in addition to Baidu, Bing most should think of IS official website help document

There is a link to help on the right side of each step, which is a detailed English document.

But don't be completely convinced, for example when configuring redirect jumps, as in the documentation:

<Outboundrules><!--This rule changes the domain of the HTTP location header for redirection responses-<RuleName= "Change Location Header"><MatchServerVariable= "Response_location"Pattern= "^http://[^/]+/(. *)"/><Conditions><add input= "{Response_ STATUS} " Pattern=" ^301 "/ > </conditions> <action type= "Rewrite"  Value= "http://{http_ Host}/{r:1} "/> </ Rule></ Outboundrules>          

I clearly feel should be 302 ah, why here is 301, and rewrite in the photo, right? I'm not sure, but also get a train of thought using the Response_status variable.

Micro-service, Nodejs seems to be very fire, I am also trying. Hope this article can let Node+nginx implementation of the domain name resolution of people more than one way to solve Node+iis+arr to achieve domain name resolution.

Reverse proxy virtual directory to Nodejs site using arr (Application Request Routing) in IIS7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.