Enable SignalR in NGINX

Hey there. Have you ever heard about SignalR? With SignalR websocket communication is very very easy. You can very easily send bi-directional messages between client and server but you can also send binary data in streams.

Everything works just fine until you get to production and you have an Nginx server as a reverse proxy. Here you need to additionally configure the proxy pass in order to enable SignalR to function.

Now to enable it, you need to go to the nginx.conf file. Determine which app is the server for SignalR. Make sure you have a stream defined for it. Supposing your location for SignalR hubs is /api/hub, add the following configuration for it:

location /api/hub {
	proxy_pass https://server-stream;
	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;

In short, you are telling Nginx to update the connection and keep it alive as bi-directional communication. This is pretty straightforward but hope it helps!

Thanks for reading, I hope you found this article useful and interesting. If you have any suggestions don’t hesitate to contact me. I also invite you to share and subscribe to the newsletter by using the buttons below! Cheers  😉

Related posts

Leave a Reply