Handshake failed due to invalid Upgrade header: null Solution and connection 60s, no information interaction, connection disconnected

Handshake failed due to invalid Upgrade header: null Solution and connection 60s, no information interaction, connection disconnected

1. Problem background: Because the backend uses the nginx proxy, an error is reported during the websocket connection process:Handshake failed due to invalid Upgrade header: null
2. Solution: Add the following code to nginx:

启用支持websocket连接

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout   3600s; // 超时设置

Description:
proxy_http_version: 1.1;(tell nginx to use HTTP/1.1 communication protocol, which is the protocol that websocket must use)
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";(tell nginx to respond to http upgrade request when it wants to use Websocket)
proxy_read_timeout 3600s;(timeout setting, 如果不设置的话,默认60s,60s内没有信息交互,将自动断开)
code screenshot:
insert image description here

Guess you like

Origin blog.csdn.net/weixin_44021888/article/details/131596608