【问题标题】:.NET 6.0: new Blazor project throws Websocket error.NET 6.0:新的 Blazor 项目引发 Websocket 错误
【发布时间】:2022-02-26 20:07:11
【问题描述】:

我目前正在运行一个带有 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 配置问题。不是我的地区。但它允许非 SSL 吗?
  • 好问题,我去看看。非 SSL 有问题吗?通常我会将所有内容都转发到 SSL。
  • 我查了一下,SSL 和非 SSL 都可用。问题仍然存在。

标签: c# nginx websocket blazor


【解决方案1】:

这里再描述一下解决方案,也许方便一点:

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

proxy_set_header Connection $connection_upgrade;

proxy_set_header Connection $http_connection;

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

【讨论】:

    猜你喜欢
    • 2021-08-12
    • 1970-01-01
    • 2022-12-01
    • 2022-10-09
    • 2014-03-13
    • 1970-01-01
    • 2019-11-09
    • 2020-04-19
    • 1970-01-01
    相关资源
    最近更新 更多