SignalR in ASP.NET Core behind Nginx SignalR in ASP.NET Core behind Nginx nginx nginx

SignalR in ASP.NET Core behind Nginx


I was able to solve this by using $http_connection instead of keep-alive or upgrade

server {  server_name example.com;  location / {    proxy_pass http://localhost:5000;    proxy_http_version 1.1;    proxy_set_header Upgrade $http_upgrade;    proxy_set_header Connection $http_connection;    proxy_set_header Host $host;    proxy_cache_bypass $http_upgrade;  }}

I did this because SignalR was also trying to use POST and GET requests to my hubs, so doing just an Upgrade to the connection in a separate server configuration wasn't enough.


The problem is the nginx configuration file. If you are using the default settings of the ASP.NET Core deployment guide then the problem is the one of the proxy headers. WebSocket requires Connection header as "upgrade".

You have to set a new path for SignalR Hub on nginx configuration file.

such as

location /api/chat {    proxy_pass http://localhost:5000;    proxy_http_version 1.1;    proxy_set_header Upgrade $http_upgrade;    proxy_set_header Connection "upgrade";    proxy_set_header Host $host;    proxy_cache_bypass $http_upgrade;}

You can read my full blog post

https://medium.com/@alm.ozdmr/deployment-of-signalr-with-nginx-daf392cf2b93