Application of application Request routing in IIS7 the graphics and text tutorial of configuring reverse proxy _win Server

Source: Internet
Author: User
When configuring a Web server, we often encounter the problem that, for some reason, the server can only have one public network IP, but may need to provide other machines or other webserver servers on the computer to visitors, but also do not want to use other ports, if under Linux, A common solution is to use Nginx as a front-end server and indirectly access other webserver via a reverse proxy. Before IIS7, it's not easy to implement this feature on Windows, but on IIS7, through application Request routing module, we can easily implement reverse proxy.

This test configuration, for simplicity, only test in IIS, configure 3 Web sites, the first "Levenweb", the use of 80 ports to provide services, the second "Levenblog", the following running levenblog2.0.9, using 8080 ports, the third "Phpweb ", there is a" test.php "Phpinfo page (iis7 PHP configuration is no longer detailed in this article), this machine ip:192.168.1.8, in order to test, we first domain binding, that is, under the leven.com.cn add 3 new subdomains, The domain binding is shown in the following illustration:

Our objectives are as follows:

http://phpweb.leven.com.cn/Visit the Phpweb site, which is http://localhost:8081/

http://levenblog.leven.com.cn/Visit the Levenblog site, which is http://localhost:8080/

http://realblog.leven.com.cn/visit the Levenblog site on the public web, that is http://leven.com.cn/

Http://localhost/leven Visit the Levenblog site, which is http://leven.com.cn/

First go to http://www.iis.net/extensions/ApplicationRequestRouting download application Request Routing, and then install, this practice is using the V2 version.

After installation, create 3 new sites:

Then locate the ARR configuration menu:

To open a proxy entry:

Then, configure the reverse proxy route under the Levenweb site, configure the UI interface or directly modify the web.config mode, this configuration gives the UI and config file two ways, and individuals prefer Config profile mode.

Enter the entry, first configure the first item, http://phpweb.leven.com.cn/visit the Phpweb site, that is http://localhost:8081/, select "Add Rules ...":

Then choose "Blank rule."

Then fill in the following:

Can't you see the picture clearly? Please click here to view the original image (larger).

This parameter sets the surface arr to intercept all requests

Continue to select "Add" in "Conditions":

The setting surface can only be passed by a URL that is http_host to phpweb.leven.com.cn, if you bind more than one domain name, depending on how many times you add or through regular expressions |

Finally, configure the proxy path in the following action:

Can't you see the picture clearly? Please click here to view the original image (larger).

Here, {r:1} represents the first matching bracket in Matchurl.

The same Web.config files are configured as follows:

Copy Code code as follows:

<rewrite>
<rules>
<rule name= "Phpweb" >
<match url= "^ (. *)"/>
<conditions>
<add input= "{http_host}" pattern= "^phpweb.leven.com.cn$"/>
</conditions>
<action type= "Rewrite" Url= "http://localhost:8081/{r:1}"/>
</rule>
</rules>
</rewrite>


The results of the test access http://phpweb.leven.com.cn/test.php are as follows:

The following can also be configured for levenblog.leven.com.cn and realblog.leven.com.cn

The UI interface configuration is no longer described, and the Web.config configuration is complete as follows:

Copy Code code as follows:

<rewrite>
<rules>
<rule name= "Levenblog" >
<match url= "^ (. *)"/>
<conditions>
<add input= "{http_host}" pattern= "^levenblog.leven.com.cn$"/>
</conditions>
<action type= "Rewrite" Url= "http://localhost:8080/{r:1}"/>
</rule>
<rule name= "Realblog" >
<match url= "^ (. *)"/>
<conditions>
<add input= "{http_host}" pattern= "^realblog.leven.com.cn$"/>
</conditions>
<action type= "Rewrite" Url= "http://leven.com.cn/{r:1}"/>
</rule>
<rule name= "Phpweb" >
<match url= "^ (. *)"/>
<conditions>
<add input= "{http_host}" pattern= "^phpweb.leven.com.cn$"/>
</conditions>
<action type= "Rewrite" Url= "http://localhost:8081/{r:1}"/>
</rule>
</rules>
</rewrite>


The results of the visit were:

And

Let's add the last item to the Http://localhost/leven agent to the http://leven.com.cn/

Copy Code code as follows:

<rule name= "leven.com.cn" >
<match url= "^leven/(. *)"/>
<conditions>
<add input= "{http_host}" pattern= "^localhost$"/>
</conditions>
<action type= "Rewrite" Url= "http://leven.com.cn/{r:1}"/>
</rule>


However, there is a problem with access, as shown in the following figure:

Obviously, there is a loss of CSS, and so on, by looking at the source:

You can see that the path to the CSS is wrong, not only that, all the img,a tag paths are all wrong, the address after the proxy is/leven/xxx, but the source address is still/xxx, so we need to add a outbound rule

The configured config file is as follows:

Copy Code code as follows:

<outboundRules>
<rule name= "Add application prefix" >
<match filterbytags= "A,img,script,link" pattern= "^/(. *)"/>
<conditions>
<add input= "{URL}" pattern= "^/leven/.*"/>
</conditions>
<action type= "Rewrite" value= "/leven/{r:1}"/>
</rule>
</outboundRules>


And then refresh:

The visible path is correct.

In the use of the reverse proxy, there are some programming places to pay attention to, in the client IP, as a result of a layer of proxy, directly is not available, therefore, we need to open

Then get the client IP by getting the X-forworded-for field in the header

From the test, arr is a very useful agent module, can fully meet the needs of our reverse proxy, not only that, ARR also provides urlrewrite,serverfarms,cache and many other functions, is worth our digging.

Source: Blog Park Author: Leven

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.