Do I need ip_hash for WebSocket load balancing?
Yes, ip_hash is critical for WebSockets. It ensures the same client always connects to the same Node.js instance. Without it, the initial HTTP upgrade and subsequent WebSocket frames might go to different instances, causing connection failures. Also use the Redis adapter for cross-instance messaging.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Nginx Load Balancing Updates Adding and Removing Backend Instances
Add a new line to the upstream block: server 127.0.0.1:3001;. Start the Node.js instance on that port (PORT=3001 pm2 start src/server.js). Test with nginx -t and reload. Nginx automatically distributes traffic to the new instance.
Mark the server as 'down' in the upstream block: server 127.0.0.1:3001 down;. Reload Nginx (stops sending new requests to it). Wait for existing requests to finish. Stop the instance (pm2 stop). Remove the line from config and reload again.
Round-robin (default, distributes in order) for most cases. least_conn for instances with different response times. ip_hash for WebSockets and sessions (same client always goes to same instance). weighted for instances with different capacities.
Still have questions?
Browse all our FAQs or reach out to our support team
