nginx .NET 6.0:新Blazor项目引发WebSocket错误

cedebl8k  于 2023-03-12  发布在  Nginx
关注(0)|答案(2)|浏览(254)

我目前正在运行一个带有ASP.NET Core 3. 1和Blazor项目的Web服务器。最近在升级到.NET 6. 0时,我遇到了(即使是空白的Blazor项目)一些问题,只有当部署在我的Web服务器上时,浏览器中才会出现WebSocket错误消息(见下面的消息)。
本地(在Windows 11 x64,VS 22 Preview 4)没有错误消息...
Web服务器:Debian 10 x64,安装了.NET 6.0 SDK,运行在NGINX上,启用了Web套接字(反向代理)。
我错过了什么,还是.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.
ubbxdtey

ubbxdtey1#

下面是再次描述的解决方案,可能更方便一些:
为了解决这个问题,我在nginx的站点配置(/etc/nginx/sites-available)中更改了以下变量:

proxy_set_header Connection $connection_upgrade;

proxy_set_header Connection $http_connection;

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

bzzcjhmw

bzzcjhmw2#

基于Bullets响应和https://nginx.org/en/docs/http/websocket.html
在/etc/nginx/sites-available上编辑您的站点配置
替换:

proxy_set_header Connection keep-alive;

其中:

proxy_set_header Connection "upgrade";

相关问题