Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx as a proxy for NodeJS+socket.io: everything is OK except for big messages

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?

like image 844
adrien Avatar asked Oct 05 '22 03:10

adrien


2 Answers

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.

like image 134
adrien Avatar answered Oct 13 '22 12:10

adrien


Try adding these with your configuration:

proxy_buffers 8 2m;
proxy_buffer_size 10m;
proxy_busy_buffers_size 10m;

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.

like image 43
user568109 Avatar answered Oct 13 '22 12:10

user568109