As explained on nginx's website I've used these settings for my nginx to proxy websockets to a NodeJS server:
location /socket.io/ {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
Everything works fine and socket.emit() / socket.on() send messages to each other; until I send a rather big text message (26 kB of html).
- this big message is not received by NodeJS (so I guess that the issue is on nginx side)
- there are no error on nginx log
- once this big message has been send by the client, NodeJS will stop receiving socket.io's heartbeats from this client.
What am I doing wrong? Is there a nginx setting that I am not aware of?
Try adding these with your configuration:
Reason : proxy_buffer default size is 4K or 8K. So it could be dropping those connections after the big message causes buffer overflow. Check the default settings here so that it meets you requirements.
The "solution" found is to use haproxy to split the tcp stream between nginx and NodeJS.
It is not optimal because it adds yet-another-program in our stack, but it does the job.
It seems to me that nginx websocket support is still far from being production-ready.