原因:
由于 Nginx 默认连接超时时间为 60s,ws需增加超时时间配置:
配置文件:
Nginx安装路径下nginx.conf 文件
配置具体内容:
# 监听8080端口
server {
listen 8080;
server_name localhost 127.0.0.1 192.168.1.147;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#设置**项目名 ws超时1h 时间
location /**/ {
proxy_pass http://127.0.0.1:7030/**/;
}
#设置项目多个ws的超时时间
location /damocles/ws*** {
proxy_pass http://127.0.0.1:7030/damocles/wsnanjingmedical;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
location /damocles/ws*** {
proxy_pass http://127.0.0.1:7030/damocles/wsdnd;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
}
优化方案:
前端设置定时请求,增加心跳逻辑
对应 - 服务端设置 超时时间可缩短
请求频率可借鉴 (blibli 心跳频率)15s