HTTP Error 502.2 - Bad Gateway IIS server ,when try to hit backend API from Front end using URL rewrite

488 Views Asked by At

I have a separate Front end application and backend application hosted in IIS

Front end application Port is 443(HTTPS) Backend Application Port is 444(HTTPS) is in Nodejs

When I try to hit the backend API https://localhost:444/apis/sample I am able to get the response

I am using URL rewrite in Front end and when I try to hit the backend api from front end site using Reverse Proxy I am getting this Error

Front end URL https://localhost/apis/sample enter image description here I am using self-signed certificate created using IIS, for making Nodejs backend as https

<rewrite>
        <rules>
            <rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
                <match url="^(apis/)(.*)" />
                <action type="Rewrite" url="https://127.0.0.1:444/{R:0}" appendQueryString="true" logRewrittenUrl="true" />
            </rule>
            <rule name="Angular Refresh Routes" stopProcessing="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="/" />
            </rule>
        </rules>
    </rewrite>
1

There are 1 best solutions below

0
samwu On

There are many reasons for 502.3 error, for troubleshooting, you can enable WinHTTP tracing via netsh. Run this command to enable tracing:

netsh winhttp set tracing trace-file-prefix="C:\Temp\WinHttpLog" level=verbose format=hex state=enabled

Then recycle the application pool to start logging. To disable tracing, run this command:

netsh winhttp set tracing state=disabled

You will find a log file in the C:\Temp directory named WinHttpLog-w3wp.exe-<pid>.<datetime>.log. Open this file and you will be able to see details of what ARR submitted to WinHTTP when generating the proxied request to send to the content node. You’ll want to search this file for the error mentioned in the Failed Request Tracing log.

For more information you can refer to this link: TROUBLESHOOTING ARR 502.3 ERRORS.