nginx代理websocket请求报400错误的问题解决

我使用nginx的86端口代理的websocket,用postman测试的时候一直报这个错,

经过测试,直接请求端口号又是正常的

那基本可以确认是nginx代理的问题出了点问题,经检查发现配置不对,调整后正常了,调整后如下

复制代码
location /websocket/{
        proxy_buffer_size  128k;
        proxy_buffers   32 32k;
        proxy_busy_buffers_size 128k;
        proxy_pass    http://127.0.0.1:7095/secondary-transaction-server/websocket/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";   
        proxy_set_header Host $host;
        proxy_connect_timeout 3s;
        proxy_read_timeout 60s;
        proxy_send_timeout 12s;
        proxy_buffering off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

其中最重要的是三个

//告诉nginx使用HTTP/1.1通信协议,这是websoket必须要使用的协议

proxy_http_version 1.1;

//下面两个是告诉nginx,如果是WebSocket时,需要响应http升级请求

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection "upgrade";

相关推荐
HIT_Weston1 天前
93、【Ubuntu】【Hugo】搭建私人博客:面包屑(一)
linux·运维·ubuntu
cuijiecheng20181 天前
Linux下Beyond Compare过期
linux·运维·服务器
喵叔哟1 天前
20.部署与运维
运维·docker·容器·.net
HIT_Weston1 天前
92、【Ubuntu】【Hugo】搭建私人博客:侧边导航栏(六)
linux·运维·ubuntu
CodeAllen嵌入式1 天前
Windows 11 本地安装 WSL 支持 Ubuntu 24.04 完整指南
linux·运维·ubuntu
今晚务必早点睡1 天前
系统通信方式实战详解:HTTP、RPC、MQ、WebSocket 各用在什么场景?(附 SDK 示例)
websocket·http·rpc
RisunJan1 天前
Linux命令-ipcs命令(报告进程间通信(IPC)设施状态的实用工具)
linux·运维·服务器
HABuo1 天前
【Linux进程(四)】进程切换&环境变量深入剖析
linux·运维·服务器·c语言·c++·ubuntu·centos
橘颂TA1 天前
【Linux】死锁四条件的底层逻辑:从锁冲突到 STL 组件的线程安全实践(Ⅵ)
linux·运维·服务器·c++·死锁