HTTP错误 502.2 – 坏网关 IIS服务器,当尝试从前端使用URL重写命中后端API时。

huangapple go评论54阅读模式
英文:

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

问题

我有一个独立的前端应用程序和后端应用程序托管在IIS中

前端应用程序端口为443(HTTPS)
后端应用程序端口为444(HTTPS)在Nodejs中

当我尝试访问后端API https://localhost:444/apis/sample
我能够获得响应

我在前端使用URL重写,当我尝试从前端站点使用反向代理访问后端API时,我收到了这个错误

前端URL https://localhost/apis/sample
HTTP错误 502.2 – 坏网关 IIS服务器,当尝试从前端使用URL重写命中后端API时。
我使用IIS创建的自签名证书,用于将Nodejs后端作为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>
英文:

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
HTTP错误 502.2 – 坏网关 IIS服务器,当尝试从前端使用URL重写命中后端API时。
I am using self-signed certificate created using IIS, for making Nodejs backend as https

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

答案1

得分: 1

502.3错误有许多原因,为了进行故障排除,您可以通过netsh启用WinHTTP跟踪。运行以下命令以启用跟踪:

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

然后重新启动应用程序池以开始记录日志。要禁用跟踪,运行以下命令:

netsh winhttp set tracing state=disabled

您将在C:\Temp目录中找到一个名为WinHttpLog-w3wp.exe-<pid>.<datetime>.log的日志文件。打开此文件,您将能够查看ARR在生成代理请求以发送到内容节点时提交给WinHTTP的详细信息。您需要在此文件中搜索Failed Request Tracing日志中提到的错误。

有关更多信息,您可以参考此链接:TROUBLESHOOTING ARR 502.3 ERRORS.

英文:

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=&quot;C:\Temp\WinHttpLog&quot; 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-&lt;pid&gt;.&lt;datetime&gt;.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.

huangapple
  • 本文由 发表于 2023年6月15日 21:04:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76482788.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定