Reverse Proxy / URL rewrite upon Request Header [Answered]RSS

3 replies

Last post Nov 14, 2016 07:46 AM by flostony

  • Reverse Proxy / URL rewrite upon Request Header

    Oct 28, 2016 12:58 PM|flostony|LINK

    Hi!

    I've got 2 Servers with 1 Public IP and 1 Domain running IIS with same Web API  but one is the production and one the beta server. I want to redirect the request internaliy to the production or the beta server upon a request header.

    for example:
    X-Environment = Production or
    X-Environment = Beta

    Is this possible to achive with ARR?

  • Rovastar Rovastar

    5457 Posts

    MVP

    Moderator

    Re: Reverse Proxy / URL rewrite upon Request Header

    Oct 28, 2016 10:50 PM|Rovastar|LINK

    sure you can create urlrewrite based on any header to route to any server farm.

    but also consider that your solution is very poor security standards anyone could add these headers in.

    Better to base it on the clients IP address.

    Troubleshoot IIS in style
    https://www.leansentry.com/
  • Re: Reverse Proxy / URL rewrite upon Request Header

    Oct 31, 2016 02:47 AM|Yuk Ding|LINK

    Hi flostony,

    You could pattern the request header by adding the following section in you rewrite rule::

                        <conditions>
                            <add input="{HTTP_X_ENVIRONMENT}" pattern="Production" />
                        </conditions>

    Besides, you could try to configure reverse  proxy based on x-environment header with the following link:

    https://www.iis.net/learn/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing

    This rewrite rule could be a demo to send the request to different server.

    <rewrite>
        <rules>
            <rule name="Reverse Proxy to webmail" stopProcessing="true">
                <match url="^webmail/(.*)" />
                <action type="Rewrite" url="http://localhost:8081/{R:1}" />
            </rule>
            <rule name="Reverse Proxy to payroll" stopProcessing="true">
                <match url="^payroll/(.*)" />
                <action type="Rewrite" url="http://localhost:8082/{R:1}" />
            </rule>
        </rules>
    </rewrite>

    Best Regards,

    Yuk Ding

    Yuk Ding

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.
  • Re: Reverse Proxy / URL rewrite upon Request Header

    Nov 14, 2016 07:46 AM|flostony|LINK

    Thanks Yuk Ding for the short example!!