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";

相关推荐
天才奇男子4 小时前
HAProxy高级功能全解析
linux·运维·服务器·微服务·云原生
小李独爱秋4 小时前
“bootmgr is compressed”错误:根源、笔记本与台式机差异化解决方案深度指南
运维·stm32·单片机·嵌入式硬件·文件系统·电脑故障
Dxy12393102165 小时前
413 Request Entity Too Large 原因与解决方案
nginx
Dying.Light6 小时前
Linux部署问题
linux·运维·服务器
CYpdpjRnUE6 小时前
光储一体机仿真模型搭建之旅
nginx
S19016 小时前
Linux的常用指令
linux·运维·服务器
萤丰信息6 小时前
AI 筑基・生态共荣:智慧园区的价值重构与未来新途
大数据·运维·人工智能·科技·智慧城市·智慧园区
小义_6 小时前
【RH134知识点问答题】第7章 管理基本存储
linux·运维·服务器
运维小欣6 小时前
Agentic AI 与 Agentic Ops 驱动,智能运维迈向新高度
运维·人工智能
_运维那些事儿7 小时前
VM环境的CI/CD
linux·运维·网络·阿里云·ci/cd·docker·云计算