nginx实现对websocket 反向代理。
keepalive_timeout 1800;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://192.168.31.96:9001;
proxy_http_version 1.1;
echo $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
- keepalive_timeout 多长时间没有读到消息就会关闭的参数,websocket 设置大一点
- 需要将客户端意图显示的传递给应用服务器
proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade;
本文介绍如何使用Nginx配置WebSocket反向代理,包括设置keepalive_timeout参数以保持连接,以及如何通过proxy_set_header正确传递客户端升级意图。

2898

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



