1.需求
前后端要求实时交互,互相通信,使用了websocket。
2.实现
修改nginx配置文件nginx.conf
1)在http块中添加以下参数
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
2)在location中 添加以下参数
location /a/b/ {
proxy_pass http://ip:port/c/d;
proxy_http_version 1.1;
proxy_connect_timeout 40s;
proxy_read_timeout 60s;
proxy_send_timeout 12s;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
/a/b---前端请求
http://ip:port/c/d---后端接口地址
3.其他
其他资料,以供参考