我正在尝试使用 nginx 1.9.11 将位置代理到上游的 websocket。以下是配置摘录:
upstream autocloud_dispatcher {
server 127.0.0.1:4000 fail_timeout=0;
}
server {
.....
location /ws {
proxy_pass http://autocloud_dispatcher;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 7d;
proxy_send_timeout 7d;
proxy_read_timeout 7d;
}
}
除此之外,我每 90 秒从备份发送一次 ping 消息。但是连接仍然每 2 分钟断开连接一次。nginx 中默认为 120 秒的其他设置?
以秒为单位设置超时对我有帮助,我的配置
location ~ /wss/(.*) {
proxy_pass http://127.0.0.1:$1;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_read_timeout 36000s;
proxy_redirect off;
}