Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS Url Rewrite overwriting external urls

On my development machine, I am trying to configure IIS as a reverse proxy to forward requests coming in port 443 to a nodejs application running locally.
The requests are getting forwarded fine, but sometimes the the nodejs application tries to redirect the browser to an external site and the IIS url rewrite module change that also to point to the local server.

I am accessing the site using https://localhost/test
IIS reroutes the requests to the node app http://localhost:14819/test
The node app returns an http 302 with location header set to https://example.com/someroute
IIS transforms this to https://localhost/someroute

I want the external urls to be untouched by IIS. How to do this? Here is my Web.config content

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />                
                <rule name="ReverseProxyInboundRule1" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="^test(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTP_HOST}" pattern="^localhost" />
                    </conditions>
                    <action type="Rewrite" url="http://localhost:14819/test{R:1}" logRewrittenUrl="true" />
                </rule>
            </rules>            
        </rewrite>        
    </system.webServer>
</configuration>
like image 833
Nimesh Madhavan Avatar asked Oct 19 '25 15:10

Nimesh Madhavan


1 Answers

If you have any redirect coming back from the backend proxy and you do not want to redirect the Location header coming ,You can do that by unchecking "Reverse rewritehost in response headers" in Application Request Routing

  • Select the server node in IIS manager
  • Go to Application Request routing Cache
  • Click on Server proxy Settings
  • UnCheck "Reverse rewritehost in response headers"
like image 102
Rohith Avatar answered Oct 22 '25 08:10

Rohith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!