Configure Nginx as a WebSocket Reverse Proxy
mainNginx (version 1.4+) can act as a front-end proxy for HTTP and WebSocket requests. To support scaling with multiple Socket.IO nodes, use the ip_hash directive in an upstream block to ensure 'sticky sessions' (routing a client to the same worker).
# Load balancing configuration
upstream socketio_nodes {
ip_hash;
server 127.0.0.1:5000;
server 127.0.0.1:5001;
server 127.0.0.1:5002;
}
server {
listen 80;
server_name _;
location / {
include proxy_params;
proxy_pass http://127.0.0.1:5000;
}
location /static/ {
alias <path-to-your-application>/static/;
expires 30d;
}
location /socket.io {
include proxy_params;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://socketio_nodes/socket.io;
}
}