Popular blog tags

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



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;


proxy_set_header Connection $http_connection;

For me this solved the problem.


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



Useful  links

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



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



Linux with Nginx conf