I have an Nginx instance which serves requests proxied to it from an haproxy. This instance should balance load between several websocket server. To get better performance the load balancing should be sticky and so i used ip_hash as the load balancing method which not works as all requests are coming from haproxy. so i tried to load balance based on x-forwarded-for header like:
upstream orderbook {
hash $http_x_forwarded_for consistent;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
}
using this method distributed load between backends but ruins session persistence (i guess so because most of the clients switch from websockets to longpolling)! What can i do to achieve LB based on real client ips?
EDIT: After trying everything most of clients switched to using websocket again by changing client connection configurations and adding:
transports: ['websocket','polling'],
It seems that in the default configuration socket.io first tries to make a long polling connection. But I wonder what was the link between using nginx load balancing and change in transport of choice by clients.