受欢迎的博客标签

.NET 6.0:  Blazor server project running on NGINX throws Websocket error

Published

 

Linux with Nginx

 

confirm that the proxy's Upgrade and Connection headers

For SignalR WebSockets to function properly, confirm that the proxy's Upgrade and Connection headers are set to the following values and that $connection_upgrade is mapped to either:

network latency

For a reasonable UI experience, we recommend a sustained UI latency of 250 ms or less.

 

.NET 6.0:  Blazor server project throws Websocket error(Upgrade and Connection headers error)

I am running currently a webserver with ASP.NET Core 6.x and a Blazor project.

Recently when upgrading to .NET 6.0 I encountered (even with a blank Blazor project) some problems with a websocket error message in the browser only when deployed on my webserver (see message below).

 

Debian 10 x64,

.NET 6.0 SDK installed,

running on NGINX with websockets enabled (reverse proxy).

 

blazor failed: Error during WebSocket handshake: Unexpected response code: 200 
(anonymous) @ blazor.server.js:1 connect @ blazor.server.js:1 _startTransport @ blazor.server.js:1 _createTransport @ blazor.server.js:1 _startInternal @ blazor.server.js:1 blazor.server.js:1
 [2022-04-23T12:29:34.498Z] Information: (WebSockets transport) There was an error with the transport.

 

Here is the solution described again, maybe a little bit more convenient:

To fix this problem, I changed in the site-configuration (/etc/nginx/sites-available) of nginx the following variables:

proxy_set_header Connection $connection_upgrade;

to

proxy_set_header Connection $http_connection;

For me this solved the problem.

 

.NET 6.0:  Blazor server project throws Websocket error(network latency error)

https://blog.csdn.net/qq_15000459/article/details/115343797

 

Useful  links

1.ngiux 反向代理项目后,发现WebSocket报404 (nginx header 设置错误)

项目开发中使用到了WebSocket,在本地使用时,一切都好使,一部署到线上WebSocket就报404,(项目中使用了ngiux做反向代理)

https://blog.csdn.net/xcc_2269861428/article/details/101904838

2.Blazor部署在Nginx反向代理+负载均衡之后偶尔WebSocket 404偶尔能正常访问(网络延迟太大造成的随机性404错误)

https://blog.csdn.net/qq_15000459/article/details/115343797

 

Linux with Nginx conf

https://docs.microsoft.com/en-us/aspnet/core/signalr/scale?view=aspnetcore-6.0#linux-with-nginx