在location匹配配置中添加如下内容:
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
示例如下:
upstream socket {
server 10.0.12.108:9000;
server 10.0.12.109:9000;
}
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://socket;
}
本文详细介绍如何在Nginx中正确配置WebSocket,包括使用proxy_http_version 1.1,设置正确的Upgrade和Connection头部,以及定义上游服务器。适用于希望优化WebSocket连接稳定性和效率的后端开发者。
341

被折叠的 条评论
为什么被折叠?



