21

nginx代理websocket,出现websocket 1006 (abnormal closure)错误

 3 years ago
source link: https://blog.csdn.net/oqqYuan1234567890/article/details/70285866
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

nginx代理websocket,出现websocket 1006 (abnormal closure)错误

original.png
皿小草 2017-04-20 18:55:21 21162
文章标签: nginx

情况:部署到服务器上的websocket程序,未加心跳,发现隔一阵子就会断开,出现1006 (abnormal closure)错误。


原因:代理参数的proxy_read_timeout默认是60s,只要超过这段时间没有通信,就会自动断开tcp连接


解决办法:

  1. 修改参数proxy_read_timeout,比如在代理设置添加 proxy_read_timeout 300s;
  2. 添加心跳,心跳的间隔要小于默认的读超时proxy_read_timeout 60s,这样程序就会可以在60s的时间窗口内读到数据,不会被nginx断开连接。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK