Skip to content

Instantly share code, notes, and snippets.

@carlssonk
Last active October 25, 2021 10:02
Show Gist options
  • Save carlssonk/32f7d56a92501c5e0b2722f394c9a841 to your computer and use it in GitHub Desktop.
Save carlssonk/32f7d56a92501c5e0b2722f394c9a841 to your computer and use it in GitHub Desktop.
How to reverse-proxy websockets & socket.io on NGINX

Minimal viable Nginx Configuration on how a reverse proxy for WebSockets might look like.

For WebSocket

location /websocket/ {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://localhost:4000; #Change 4000 to whatever port your app runs on.
}

For Socket.io

location /socket.io/ {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://localhost:4000/socket.io/; #Change 4000 to whatever port your app runs on.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment