简体   繁体   中英

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. 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. The steps I took at the IIS INSTANCE level:

  1. Set up a web farm - only one server in it, machine2
  2. Set up a rewrite for '*'
  3. Tested against ' http://machine1/site1/api/api1 ' - it was successfully routed to machine2/site1/api/api1
  4. Changed inbound rule from Wildcard to Regular Expressions
  5. Changed Pattern to '. (/. /api/.*)' (without the single quotes)
  6. Tested against ' http://sarjhennew10vm/site1/api/api1 '
  7. Request was not routed to machine 2.

Below is a snippet from my applicationHost.config [the root of 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?

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}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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