avatar
童琦杰
Feb 2, 2019Technology

NGINX - 配置WebSocket代理

HTTP Upgrade机制可以用来将HTTP连接升级到WebSocket连接,需要用到UpgradeConnection头。对于代理服务器,需要将来自客户端的Upgrade请求带到后端服务器上,同时保持长连接。

nginx
location /ws/ {
    proxy_pass http://wsbackend;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
}
© 2015-2022 tongqijie.com 版权所有沪ICP备17000682号