简体   繁体   English

IIS 反向代理/全局 URL 重写所有站点的“/api/”文件夹

[英]IIS Reverse proxy/Global URL Rewrite for “/api/” folder for all sites

I would like to reverse proxy any requests to an IIS instance for any sites where the request is in the '/api/' folder.对于请求位于“/api/”文件夹中的任何站点,我想将任何请求反向代理到 IIS 实例。 I set up a server farm and have the reverse proxy working for everything using the '*' wildcard, but when I want to limit the scope to a RegEx it will not rewrite/proxy to the backend server.我设置了一个服务器场,并让反向代理使用“*”通配符为所有内容工作,但是当我想将 scope 限制为 RegEx 时,它不会重写/代理到后端服务器。 The steps I took at the IIS INSTANCE level:我在 IIS INSTANCE 级别采取的步骤:

  1. Set up a web farm - only one server in it, machine2设置一个 web 场 - 其中只有一台服务器,机器 2
  2. Set up a rewrite for '*'为“*”设置重写
  3. Tested against ' http://machine1/site1/api/api1 ' - it was successfully routed to machine2/site1/api/api1针对“ http://machine1/site1/api/api1 ”进行测试 - 它已成功路由到 machine2/site1/api/api1
  4. Changed inbound rule from Wildcard to Regular Expressions将入站规则从通配符更改为正则表达式
  5. Changed Pattern to '.将模式更改为 '. (/. /api/.*)' (without the single quotes) ( /./api/.*)' (不带单引号)
  6. Tested against ' http://sarjhennew10vm/site1/api/api1 '针对“ http://sarjhennew10vm/site1/api/api1 ”进行测试
  7. Request was not routed to machine 2.请求未路由到机器 2。

Below is a snippet from my applicationHost.config [the root of IIS].下面是我的 applicationHost.config [IIS 的根目录] 的一个片段。

    <rewrite>
        <globalRules>
            <rule name="ARR_Farm1_loadbalance" patternSyntax="ECMAScript" stopProcessing="true">
                <match url=".*(\/.*\/api\/.*)" />
                <action type="Rewrite" url="http://Farm1/{R:1}" />
            </rule>
        </globalRules>
    </rewrite>
    <proxy enabled="true" />

Is it possible to to a global URL re-write to the server farm for any site on the instance for specific folders?是否可以将全局 URL 重新写入服务器场以针对特定文件夹的实例上的任何站点?

Edit: It was answered below - I am including a picture in case others run into this.编辑:它在下面得到了回答——我附上了一张照片,以防其他人遇到这个问题。 The test pattern isn't clear to me - and counters documentation found here .测试模式对我来说不是很清楚 - 并且计数器文档在这里找到

IIS 中的测试模式匹配

Your pattern is incorrect, you can try below code, and change the rewrite url to https://Farm1/ {R: 0}您的模式不正确,您可以尝试以下代码,并将重写 url 更改为https://Farm1/ {R: 0}

<rule name="ARR_Farm1_loadbalance" patternSyntax="ECMAScript" stopProcessing="true">
    <match url=".*(\/api\/.*)" />
    <action type="Rewrite" url="https://Farm1/{R:0}" />
</rule>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM