IIS的反向代理是经过ARR模块来完成的,ARR模块须要另外安装,并且只能经过Web PlatForm Installer安装。关于安装来源与步骤,帖子已有不少,不作描述。启用“Application Request Routing”功能以及简单设置URL Rewrite的步骤也不作描述,帖子不少,几乎是千篇一概的贴图,意义不大。在此只记录一些知识要点:html
一、规则设置中的第一个步骤“匹配URL”,匹配来源仅仅是请求的完整URL中除去协议、主机头、端口号、querystring后剩下的那一部分:正则表达式

好比,预计浏览器的请求地址为:http://szh-it-2e02d/test/KWF/Preview.html?ticket=b037ec8c-6579-4e27-be43-dfc3e821c2d2&flowID=1278355,那么仅仅是”test/KWF/Preview.html“这一段会用于匹配测试。所产生的捕获组“{R:0}”“{R:1}”,即为正则表达式执行时匹配成功的块,数目因正则的不一样而不一样,将做为变量,可在后面的配置中引用。浏览器
二、“条件”这一块设置中,条件输入必须是可用的变量,而可使用的变量有哪些呢?微软的帮助文档url-rewrite-module-configuration-reference一文已经列举得很清楚:服务器
For an HTTP URL in this form: http(s)://<host>:<port>/<path>?<querystring>测试
- The <path> is matched against the pattern of the rule.
- The <querystring> is available in the server variable called QUERY_STRING and can be accessed by using a condition within a rule.
- The <host> is available in the server variable HTTP_HOST and can be accessed by using a condition within a rule.
- The <port> is available in the server variable SERVER_PORT and can be accessed by using a condition within a rule.
- Server variables SERVER_PORT_SECURE and HTTPS can be used to determine if a secure connection was used. These server variables can be accessed by using a condition within a rule.
- The server variable REQUEST_URI can be used to access the entire requested URL path, including the query string.
每一条规则,能够设置零到若干个条件,只有知足步骤1中的URL模式匹配时,才会进入步骤2的“条件”验证,只有知足条件验证,才会进入后续的处理。若是设置了条件,那么也会产生一些变量值,形如{C:0}{C:1},可在后续中使用。this
界面上的条件设置只有按正则匹配这一种方式,实际上还有另外两种,但不支持可视化操做,须要手工编写配置文件。url
- IsFile – This match type is used to determine whether the input string contains a physical path to a file on a file system. If a condition input string is not specified, the URL Rewrite Module uses the physical path of the requested file as a default value for the condition input. This match type can be used only for distributed rules.
- IsDirectory – This match type is used to determine whether the input string contains a physical path to a directory on a file system. If a condition input string is not specified, the URL Rewrite Module uses the physical path of the requested file as a default value for the condition input. This match type can be used only for distributed rules.
三、服务器变量。这一步能够自由添加一些变量值,也能够修改变量值,如:指望把端口从80转到81,能够作以下配置:3d

四、操做。这一步骤里首先要选择操做类型,若是是要作反向代理,那么应该选择“重写”这一种类型。重写的URL中,可使用变量、常量来描述,好比:代理

五、很重要也是颇有用的一点,使用反向代理时,客户端(浏览器)只须要可以访问反向代理服务器便可,与代理后的目标服务器是不产生直接访问的,代理充当了一个请求转发的做用。这一点已作验证。orm