【已解决】Nginx设置代理,wss无法连接

water2023

问题描述

workerman正常启动,但是无法链接wss服务,直接访问域名/wss/,正常应该显示websocket,但是目前显示502 bad gateway,有一个很久的帖子类似问题,问题定位在nginx的wss代理配置上,但是试了没有找到问题,服务器也重启过,防火墙也关闭了。
配置了两套服务器,有一台是ok的,另外这台折腾好久还是不行,求大佬支招~

location /wss/
{
proxy_pass http://127.0.0.1:8282;
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;
}





程序代码


// gateway 进程,这里使用Text协议,可以用telnet测试
$gateway = new Gateway("websocket://0.0.0.0:8282");
// gateway名称,status方便查看
$gateway->name = 'T1111Gateway';
// gateway进程数,一般设置2个就足够
$gateway->count = 2;
// 本机ip,分布式部署时使用内网ip
$gateway->lanIp = '127.0.0.1';
// 内部通讯起始端口,假如$gateway->count=2,起始端口为2900
// 则一般会使用2900 2901 2个端口作为内部通讯端口 
$gateway->startPort = 2900;
// 服务注册地址
$gateway->registerAddress = '127.0.0.1:1238';

//心跳间隔
$gateway->pingInterval = 10;
//心跳数据
$gateway->pingData = '{"type":"ping"}';

报错信息

var socket = new WebSocket("wss://域名/wss/");

截图报错信息里报错文件相关代码

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

php 7.4
workerman 4.1.11

961 2 0
2个回答

water2023

一样的配置,两台服务器,有一台链接不上,求支招~

18266

nginx配置
upstream webman {
server 127.0.0.1:8787;
keepalive 10240;
}
server
{
listen 80;
listen 443 ssl http2;
server_name demo.aa.com 74.demo.aa.com;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/webman.aa.com/public;

CERT-APPLY-CHECK--START

# 用于SSL证书申请时的文件验证相关配置 -- 请勿删除
include /www/server/panel/vhost/nginx/well-known/demo.aa.com.conf;
#CERT-APPLY-CHECK--END

#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
ssl_certificate    /www/server/panel/vhost/cert/demo.aa.com/fullchain.pem;
ssl_certificate_key    /www/server/panel/vhost/cert/demo.aa.com/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CMD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
error_page 497  https://$host$request_uri;

proxy_buffering  off;

#SSL-END

#ERROR-PAGE-START  错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END

#PHP-INFO-START  PHP引用配置,可以注释或修改
include enable-php-00.conf;
#PHP-INFO-END

#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/demo.aa.com.conf;
#REWRITE-END

#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
{
    return 404;
}

#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
    allow all;
}

#禁止在证书验证目录放入敏感文件
if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
    return 403;
}

location ~ .*\.(js|css|gif|jpg|jpeg|png|bmp|swf|b3dm)$
{
    expires      12h;
    error_log /dev/null;
    access_log /dev/null;
}

# WSS站内消息推送
location /app/fnSEwg1b2UAXXXXXXXXXXXXXXXXXXX
{
    proxy_pass http://127.0.0.1:2345;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header X-Real-IP $remote_addr;
}

# 特定路径代理配置
location ^~ /plugin/webman/push/ {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_pass http://webman;
}

location / {
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header Host $host;
  proxy_http_version 1.1;
  proxy_set_header Connection "";

  # 其他请求发送给后端服务器处理
  if (!-f $request_filename){
      proxy_pass http://webman;
  }
}
access_log  /www/wwwlogs/demo.aa.com.log;
error_log  /www/wwwlogs/demo.aa.com.error.log;

}
阿里云slb负载配置
截图
截图

  • 暂无评论
×
🔝