Enable SignalR in NGINX

Share this post on:

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. If you found my content useful please consider a small donation. Any support is greatly appreciated! Cheers  😉

Hi there 👋
It’s nice to meet you.

Sign up to receive useful content in your inbox, every month.

Spam is a waste of time, I prefer something creative! Read the privacy policy for more info.

Share this post on:

Author: afivan

Enthusiast adventurer, software developer with a high sense of creativity, discipline and achievement. I like to travel, I like music and outdoor sports. Because I have a broken ligament, I prefer safer activities like running or biking. In a couple of years, my ambition is to become a good technical lead with entrepreneurial mindset. From a personal point of view, I’d like to establish my own family, so I’ll have lots of things to do, there’s never time to get bored 😂

View all posts by afivan >