IIS proxy reverse

Viewed 13

Pay attention to the following examples.

subdomain1.sample.com => target.sample.com/1001
subdomain1.sample.com/order => target.sample.com/1001/order
subdomain1.sample.com/login => target.sample.com/1001/login

subdomain2.sample.com => target.sample.com/1002
subdomain2.sample.com/order => target.sample.com/1002/order
subdomain2.sample.com/login => target.sample.com/1002/login

A reactjs project is running on target.sample.com, which is as follows

/          ==>‌ page not found
/:id       ==> home
/:id/login ==> page login
/:id/order ==> page order

We want to do this in IIS with the help of proxy reverse or rewrite.

Below are the settings of the web.config file related to the subdomain1.sample.com address

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="http_to_https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
                </rule>
                <rule name="proxy" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="https://target.sample.com/1001/{R:1}" />
                </rule>
            </rules>
            <outboundRules>
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                    <match filterByTags="A, Form, Img" pattern="^https://target.sample.com/1001/(.*)" />
                    <action type="Rewrite" value="https://subdomain1.sample.com/{R:1}" />
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
        <httpErrors errorMode="Custom" existingResponse="Replace">
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" path="https://{HTTP_HOST}{REQUEST_URI}" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
</configuration>

such an error can be seen in the browser console

Uncaught SyntaxError: Unexpected token '<' (at main.697bcedd.js:1:1)

Have I gone the wrong way? How can I solve this problem?

0 Answers
Related