I'm a bit confused. I'm using socket.io on my NodeJS Server using a simple:
const server = http.createServer(app);
const io = socketIo();
io.attach(server);
io.adapter(redisAdapter(process.env.REDISCLOUD_URL));
server.listen(3000)
Now I clustered my server process using PM2 Cluster option.
My nginx configuration is straight forward as follows:
location / {
proxy_pass http://localhost:5030;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
Should I also add websocket transport instead of the normal http polling?
const server = http.createServer(app);
const io = socketIo();
io.attach(server, {
transports: [ 'websocket' ]
});
io.adapter(redisAdapter(process.env.REDISCLOUD_URL));
server.listen(3000)
In socket.io website they recommend against it and they suggest instead to balance load between nodes using upstream in the nginx.conf file with sticky session as follows:
upstream nodes {
# enable sticky session based on IP
ip_hash;
server app01:3000;
server app02:3000;
server app03:3000;
}
But my I don't have app01, app02 and app03. I have my PM2 processes, but they all reside on the same localhost:5030 address. So am I left only with the choice of enabling websocket transport and losing the fallback option for long-polling?