通过nginx访问连接websocket 错误 failed: Error during WebSocket handshake: Unexpected response code: 400

简介: 通过nginx访问连接websocket 错误 failed: Error during WebSocket handshake: Unexpected response code: 400

最近项目部署到正式环境的时候发现页面websocket连接错误。如下:


其中与本地环境的区别就是正式环境配置了nginx

而我通过真实路径访问正式环境项目,也能正常连接。经查阅相关资料,在nginx.conf 配置文件中location 加入如下参数即可:

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 3600s;

其中第一行是告诉nginx使用HTTP/1.1通信协议,这是websoket必须要使用的协议。


第二行和第三行告诉nginx,当它想要使用WebSocket时,响应http升级请求。


socket.io 官方issues有关于这个问题的讨论,链接:https://github.com/socketio/socket.io/issues/1942

目录
相关文章
|
7月前
|
应用服务中间件 nginx
Nginx nginx: [error] open() "/usr/local/var/run/nginx.pid"
Nginx nginx: [error] open() "/usr/local/var/run/nginx.pid"
91 0
|
9天前
|
应用服务中间件 nginx
yum 安装报错 No package nginx available Error:Nothing to do
yum 安装报错 No package nginx available Error:Nothing to do
24 1
|
16天前
|
应用服务中间件 nginx Windows
【报错】Windows下启动nginx报:bind() to 0.0.0.0:80 failed...
【报错】Windows下启动nginx报:bind() to 0.0.0.0:80 failed...
|
1月前
|
算法 应用服务中间件 网络安全
windows下采用 nginx配置websocket支持wss流程
windows下采用 nginx配置websocket支持wss流程
|
7月前
|
应用服务中间件 nginx
Mac Nginx nginx: [error] open() “/usr/local/var/run/nginx.pid“
Mac Nginx nginx: [error] open() “/usr/local/var/run/nginx.pid“
59 1
|
3月前
|
存储 应用服务中间件 nginx
【各种问题处理】nginx报错nginx: [error] open() “/run/nginx.pid” failed (2: No such file or directory)
【1月更文挑战第13天】【各种问题处理】nginx报错nginx: [error] open() “/run/nginx.pid” failed (2: No such file or directory)
|
5月前
|
JavaScript 前端开发 Ubuntu
nginx部署vue后显示500 Internal Server Error解决方案
nginx部署vue后显示500 Internal Server Error解决方案
139 0
|
5月前
|
负载均衡 安全 应用服务中间件
Nginx实现websocket代理的方式
Nginx实现websocket代理的方式
84 0
|
5月前
|
JavaScript 前端开发 Ubuntu
nginx部署vue后显示500 Internal Server Error解决方案
nginx部署vue后显示500 Internal Server Error解决方案
164 0
|
6月前
|
应用服务中间件 nginx
【Nginx异常】[error] 4236#29900: OpenEvent(“Global\ngx_reload_27128“) failed (5: Access is denied)
【Nginx异常】[error] 4236#29900: OpenEvent(“Global\ngx_reload_27128“) failed (5: Access is denied)
159 0