通过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

目录
相关文章
|
2月前
|
应用服务中间件 nginx
nginx error日志 client intended to send too large body: 1434541 bytes 如何处理?
【8月更文挑战第27天】nginx error日志 client intended to send too large body: 1434541 bytes 如何处理?
39 6
|
5月前
|
应用服务中间件 nginx
yum 安装报错 No package nginx available Error:Nothing to do
yum 安装报错 No package nginx available Error:Nothing to do
238 1
|
5月前
|
应用服务中间件 nginx Docker
Docker中报错 Error response from daemon: Conflict. The container name “/nginx01“ is already in use
在尝试运行 `docker run -d --name nginx01 -p 3344:80 nginx` 时遇到错误。问题源于已有名为 nginx01 的容器未正确终止,造成命名冲突。解决方法:首先使用 `docker ps -a` 查看所有容器,然后删除现有 nginx01 容器,执行 `docker rm <container_id>`(替换 `<container_id>` 为实际容器ID),最后再运行 `docker run` 命令即可。
225 0
|
5月前
|
安全 Ubuntu 应用服务中间件
【报错】ubutun下启动nginx失败:500 internal server error
【报错】ubutun下启动nginx失败:500 internal server error
500 0
|
5月前
|
应用服务中间件 nginx Windows
【报错】Windows下启动nginx报:bind() to 0.0.0.0:80 failed...
【报错】Windows下启动nginx报:bind() to 0.0.0.0:80 failed...
123 0
|
5月前
|
应用服务中间件 nginx 容器
error: a container name must be specified for pod pod-base, choose one of: [nginx busybox]
error: a container name must be specified for pod pod-base, choose one of: [nginx busybox]
69 0
|
5月前
|
算法 应用服务中间件 网络安全
windows下采用 nginx配置websocket支持wss流程
windows下采用 nginx配置websocket支持wss流程
431 0
|
5月前
|
存储 应用服务中间件 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)
|
11月前
|
JavaScript 前端开发 Ubuntu
nginx部署vue后显示500 Internal Server Error解决方案
nginx部署vue后显示500 Internal Server Error解决方案
301 0
|
11月前
|
负载均衡 安全 应用服务中间件
Nginx实现websocket代理的方式
Nginx实现websocket代理的方式
139 0
下一篇
无影云桌面