help setting up reverse proxy in IIS with ARR and URL Rewrite

Lance Lyons 86 Reputation points
2023-02-12T17:21:48.8766667+00:00

Hi, We are trying to setup a reverse proxy on a Windows 2019 server with IIS, ARR 3.0 and URL Rewrite.

We are wanting to take incoming requests from https://beta-services.companyname.com/avatars/*.jpg and pull them from https://beta-services2.companyname.com/avatars/*.jpg. beta-services is external in DMZ and reachable by our customers but beta-services2 is not (it is reachable from the servers hosting beta-services.companyname.com.

We also have other apis running under beta-services.companyname.com like beta-services.companyname.com/api1name, beta-services.companyname.com/api2name, etc. that we dont want to have any change too.

We have enabled ARR proxy and setup the following rules for https://beta-services.companyname.com in the web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)/avatars" />
                    <conditions>
                        <add input="{QUERY_STRING}" pattern="/avatars" />
                    </conditions>
                    <action type="Rewrite" url="{C:1}://beta-services2.companyname.com/{R:1}" />
                </rule>
            </rules>
            <outboundRules>
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                    <match filterByTags="A, Form, Img" pattern="^http(s)?://beta-services2.companyname.com/(.*)" />
                    <action type="Rewrite" value="http{R:1}://beta-services.companyname.com/{R:2}" />
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

the images of the rules are as follows

Inbound

ReverseProxy

In bound Rules

ReverseProxyRules

and outbound rules

ReverseProxyOutbound

Requests to https://beta-services.companyname.com/avatars/filename.jpg just throw 404 errors

requests to https://beta-services.companyname.com/api1name throw 500 errors

What am I doing wrong

thanks

Windows development | Internet Information Services
{count} votes

1 answer

Sort by: Most helpful
  1. Lance Lyons 86 Reputation points
    2023-02-14T20:32:45.1966667+00:00

    This worked for us in this example.

    
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="AvatarsRp" stopProcessing="true">
                        <match url="avatars/(.*)" />
                        <action type="Rewrite" url="https://env-services2.companyname.com/{R:0}" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.