nginx 转发 wss 协议

morris

问题描述

使用nginx 做wss转发
通过 在浏览器直接 https://domain/wss_socket 能正常响应
截图

在浏览器 console :
截图

会一直等待、 一段时间后:
截图

程序代码

nginx配置

location /wss_socket
  {
    proxy_pass http://127.0.0.1:2345;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    rewrite /wss/(.*) /$1 break;
    proxy_redirect off;
  }

报错信息

操作系统及workerman/webman等框架组件具体版本

workerman 以及 php 版本
截图

操作系统
截图

nginx 版本
截图

1459 5 1
5个回答

静默

参考手册 wss nginx代理配置
把手册里没有的多余的配置干掉

  • 暂无评论
oliusha

干掉这两句看看

rewrite /wss/(.*) /$1 break;
proxy_redirect off;
Tinywan

看看防火墙、本地代理有没有开

  • morris 2022-11-16

    本地代理肯定是开了的、 直接访问端口 都能看到 websocket的字样
    防火墙是没开的、

morris

原因是 服务器走咯 阿里云的 数字证书服务、
不管前台是否是https 进行访问
到nginx层 都是http 请求、 所以配置不成功;

  • 暂无评论
owenzhang
  • 暂无评论
年代过于久远,无法发表回答
🔝