background
这天气够热的,要处理的事情也够多的。。。。
want to see the solution, direct ctrl+f search keyword ' configuration point '
The beginning of the confession (to see the reason for this, personal opinion, does not mean right)
Explanation: Today with nginx anti-generation communication project, found that the average 1 minutes or so, there will be websocket connection interruption, and then look at a bit, is the problem of Nginx.
The reason is: nginx waiting for your first communication and the second communication time difference , more than it set the maximum waiting period , in short, the timeout , so it snapped a broken, Start the resolution step.
Solution One
其实只要配置nginx.conf的对应localhost里面的这几个参数就好
1. Proxy_connect_timeout;
2. Proxy_read_timeout;
3. Proxy_send_timeout;
Solutions Two
发心跳包,原理就是在有效地再读时间内进行通讯,重新刷新再读时间
Note: The location of the configuration is localhost, giving a brief address
http {server {location/{root html index index.html index.htm; Proxy_pass http://webscoket; proxy_http_version 1.1; proxy_ Connect_timeout 4s; #配置点1 proxy_read_timeout 60s; #配置点2, if not effective, you can consider this time configuration long proxy_send_timeout 12s; #配置点3 proxy_set_header Upgrade $http _upgrade; #这是webSocket的配置, unrelated to this blog Proxy_set_header Connection #这是webSocket的配置, not related to this blog}}}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
Explanation of Configuration 2
Note : This is the server for you to wait for the maximum time , that is, when you websocket using Nginx forwarding, with the above configuration 2, if there is no communication within 60 seconds , will still be disconnected , so you can set it according to your needs.
Example:
For example, I set 10 minutes, then if I have 10 minutes of communication, or 10 minutes of heartbeat, it is possible to keep the connection uninterrupted, detailed view of individual needs
Http://nginx.org/en/docs/http/websocket.html
Nginx Agent WebSocket frequently interrupted solution, how to maintain long connection