Incompatibile SockJS! Main site uses: "1.1.5", the iframe: "1.0.0"

本文详细介绍了如何在Nginx中正确配置WebSocket代理,解决了因代理设置不当导致的WebSocket连接失败问题。通过修改Nginx配置文件,启用HTTP/1.1协议,并设置必要的升级头,成功实现了WebSocket服务的正常运行。

目录

一、问题描述:

二、问题解决


一、问题描述:

公司有个项目用到了websocket,在本地环境测试没有问题,因为公司后台websocket是微服务搭建,我们需要nginx进行一层代理,结果出现如下错误

错误1:WebSocket failed: Error during WebSocket handshake: Unexpected response code: 400

错误2:Incompatibile SockJS! Main site uses: "1.1.5", the iframe: "1.0.0"

二、问题解决

1、首先找到自己nginx的配置文件—>配置下面代码 ——> nginx重启

location /consultation-websocket/ {
	  proxy_pass http://127.0.0.1:8098/consultation-websocket/;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;

      # For WebSocket upgrade header
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
}

2、其中最重要的是下面这三行

proxy_http_version 1.1;(告诉nginx使用HTTP

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值