DEV Community

ente
ente

Posted on • Originally published at ente.io

Proxying websockets via nginx

Be me. Have an existing nginx config setup that works for HTTP, but now big guy ask me to also tunnel websocket connections through it.

In the nginx conf, in the http section, add these

http {
    ...

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

    ...
}
Enter fullscreen mode Exit fullscreen mode

In the nginx conf, in the http > server > location section, add

http {
    ...

    server {
        ...

        location ... {
            ...

            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;

            ...
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Poke nginx

systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

Everything works!

Be me. Go back to watching TV.

Top comments (0)