why deepstreamHub? compare us getting started faq
use cases
blog contact

What is nginx?

Nginx (pronounced engine-x) is a multi purpose webserver. It's one of the most widely used HTTP servers and powers sites such as GitHub or reddit. Aside from serving static files via HTTP, it can be used as a reverse proxy, multi protocol load balancer or container for fast CGI scripts

Nginx deepstream

Using nginx and deepstream

Nginx can be used as a web-facing reverse proxy and load balancer in front of deepstream servers.

A simple deployment with nginx and deepstream If you are planning on using a message bus, please head over to our enterprise offering

Reverse Proxy

For HTTP deployments it is common practice to not directly expose the webserver to the internet, but instead place a different server in front of it. For deepstream.io production deployments we highly recommend doing the same. This "reverse proxy" handles tasks like SSL termination (decrypting incoming messages via WSS ) and high availability / error reporting (e.g. replying to requests with a 500 status if the underlying server is unavailable).

Load Balancer

deepstream can scale horizontally via clustering. If you want to provide a single URL for clients to connect to your cluster, you need to place something in front that distributes incoming connections between the available servers: a load balancer. Load balancing persistent connections can be a bit tricky sometimes. deepstream supports connections made via WebSockets.

Alternatives to nginx

Instead of nginx you could also use e.g. HA Proxy or Apache

What about AWS Elastic Load Balancer?

If you're deploying deepstream on AWS, you'd probably want to use Amazon's well integrated load balancing service ALB. It allows you to combine ssl termination, load balancing and health-checks for easy deployment.

Installing nginx for use with deepstream

By default, Nginx comes with everything you need to use it as an HTTP server. You can install it from the repositories provided by your favorite distribution. On a rpm based linux-distribution e.g. like it would be:

yum update
yum install -y nginx

Configuring nginx as a proxy / load balancer

The following configuration shows how to use nginx as a load balancer, SSL termination point and reverse proxy for HTTP and Websocket connections. If you only want to use parts of this functionality, remove the unneeded bits.

worker_processes  1;

events {
    worker_connections  1024;

http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;

    upstream websocket {
      server localhost:6020;
    upstream httpendpoint {
      server localhost:8080;

    server {
       listen 9090;

       # Deepstream websocket redirect
       location /deepstream {
            proxy_pass http://websocket;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection '$connection_upgrade;
            rewrite ^/deepstream(.*) $1 break;

      # Deepstream http endpoint
      location /http {
           proxy_pass http://httpendpoint;
           proxy_http_version 1.1;
           rewrite ^/http(.*) $1 break;