简体   繁体   English

添加 Microsoft.Extensions.Http 后出现错误的网关 502 响应

[英]Bad Gateway 502 responses after adding Microsoft.Extensions.Http

I was refactoring my .NET core 2.2 based Web Api to make use of reusable a HttpClient.我正在重构基于 .NET 核心 2.2 的 Web Api 以使用可重用的 HttpClient。 It all looked fine.一切看起来都很好。 But in the end my Api only threw 502 Bad Gateway errors.但最后我的 Api 只抛出了 502 Bad Gateway 错误。

Now, to find out what causes this unexpected behaviour, I went back a few steps in my refactoring work.现在,为了找出导致这种意外行为的原因,我在重构工作中退回了几步。 I found that only adding the Microsoft.Extensions.Http package to my project is what makes my application start to throw those 502's.我发现只有将 Microsoft.Extensions.Http package 添加到我的项目中才能使我的应用程序开始抛出那些 502。

So no code changes, just adding the package via NuGet.因此无需更改代码,只需通过 NuGet 添加 package。 I added Microsoft.Extensions.Http version 5.0.0.0.我添加了 Microsoft.Extensions.Http 版本 5.0.0.0。

Does anyone have a clue why this is?有谁知道这是为什么?

I'm running my app in debug mode in Visual Studio 2022 / IISExpress我在 Visual Studio 2022 / IISExpress 中以调试模式运行我的应用程序

.NET doesn't typically return a 502 status code, so this error is most likely with your hosting setup. .NET 通常不返回 502 状态代码,因此此错误很可能与您的托管设置有关。

502 - Bad Gateway is typically returned by a load balancer / reverse proxy when either there are no nodes in the pool (ie the application didn't start up properly), or the node crashes while servicing the request. 502 - Bad Gateway

In either case, you'll need to check the logs on the host to see which case is correct.无论哪种情况,您都需要检查主机上的日志以查看哪种情况是正确的。 My guess is if this started happening after you installed the package, the runtime on the server is incompatible with it or the package is simply misconfigured.我的猜测是,如果这在您安装 package 后开始发生,服务器上的运行时与它不兼容,或者 package 只是配置错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM