Websocket is a network transport protocol that allows full-duplex communication over a single TCP connection. Websocket makes it easier to exchange data between the client and the server, allowing the server to actively push data to the client.In the WebSocket API, the browser and the server only need to complete a handshake, a persistent connection can be established between the two, and bidirectional data transfer.

Nginx configuration Websocket listening to different http ports, the beginning of the protocol display is different, listening to port 80 is ws://, listening to port 443 is wss://.

The nginx.conf file http{} segment adds the

Terminal window
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

nginx.conf file server{} location segment add

Terminal window
location /test/ {
......
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Origin "";
}

Just reload Nginx to match.