问题:.NET 6.0:新的 Blazor 项目引发 Websocket 错误

我目前正在运行一个带有 ASP.NET Core 3.1 和一个 Blazor 项目的网络服务器。最近在升级到 .NET 6.0 时,我遇到了一些问题(即使是一个空白的 Blazor 项目),仅当部署在我的网络服务器上时,浏览器中的 websocket 错误消息才会出现一些问题(请参阅下面的消息)。

在本地(在 Windows 11 x64、VS 22 Preview 4 上)没有错误消息...

网络服务器:Debian 10 x64,安装了 .NET 6.0 SDK,在 NGINX 上运行并启用了 websockets(反向代理)。

我错过了什么,还是 .NET 6.0 和 NGINX 的当前状态有问题?我已经尝试在 debian 服务器上本地访问网页,并且出现相同的错误消息。

帮助将不胜感激!

问候!

订单内的错误信息:

Information: Normalizing '_blazor' to 'http://192.168.178.35/_blazor'.

blazor.server.js:1 WebSocket connection to 'ws://192.168.178.35/_blazor?id=wnPt_fXa9H4Jpia530vPWQ' failed:

Information: (WebSockets transport) There was an error with the transport.

Error: Failed to start the transport 'WebSockets': Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.

Warning: Failed to connect via WebSockets, using the Long Polling fallback transport. This may be due to a VPN or proxy blocking the connection. To troubleshoot this, visit https://aka.ms/blazor-server-using-fallback-long-polling.

解答

这是再次描述的解决方案,也许更方便一点:

为了解决这个问题,我在 nginx 的站点配置(/etc/nginx/sites-available)中更改了以下变量:

proxy_set_header Connection $connection_upgrade;

proxy_set_header Connection $http_connection;

对我来说,这解决了问题。

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐