Nginx 配置 WebSocket 反向代理

在nginx.conf配置添加map指令

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

配置虚拟主机

upstream websocket {
    server 1.2.3.4:80;
}

location ^~ /websocket {
    proxy_pass http://websocket;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}