关于webman push 无法连接 【已解决】

破建站的

问题原因

config目录多了一个plugin.php的配置文件,这个文件里的部分配置恰巧会影响的push文件中的端口号 导致websocket无法连接

我已经删除了该文件 慎用config/plugin.php的配置 最好不要去定义他

问题描述

以前也做过了很多次了 今天新的项目死活连不上 用老项目现在也连不上 没辙了

希望大佬帮我看看是哪的问题

程序代码

//app.php
[
    'enable'       => true,
    'websocket'    => 'websocket://0.0.0.0:3131',
    'api'          => 'http://0.0.0.0:3232',
    'app_key'      => 'xxxxx',
    'app_secret'   => 'xxxxxxx',
    'channel_hook' => 'http://127.0.0.1:8787/plugin/webman/push/hook',
    'auth'         => '/plugin/webman/push/auth'
]

//process.php
[
    'server' => [
        'handler'     => Server::class,
        'listen'      => config('plugin.webman.push.app.websocket'),
        'count'       => 1, // 必须是1
        'reloadable'  => false, // 执行reload不重启
        'constructor' => [
            'api_listen' => config('plugin.webman.push.app.api'),
            'app_info'   => [
                config('plugin.webman.push.app.app_key') => [
                    'channel_hook' => config('plugin.webman.push.app.channel_hook'),
                    'app_secret'   => config('plugin.webman.push.app.app_secret'),
                ],
            ]
        ]
    ]
]
//nginx
upstream webman {
    server 127.0.0.1:8795;
    keepalive 10240;
}
location ^~ / {
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    if (!-f $request_filename){
        proxy_pass http://webman;
    }
}
location ~ "^/app/[a-zA-Z0-9_-]{16,32}$" {
    proxy_pass http://127.0.0.1:3131;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header X-Real-IP $remote_addr;
}

//连接代码
var webman_push = new Push({
    url: 'ws://' + window.location.hostname,
    app_key: 'bbaa660689dc6546f237056ac495af3e',
    auth: '/plugin/webman/push/auth' // 订阅鉴权(仅限于私有频道)
});

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

push.js:245 WebSocket connection to 'ws://yingshi.com/app/bbaa660689dc6546f237056ac495af3e' failed:

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

这里写具体的系统环境相关信息
docker环境 外部开启了8795端口

94 4 0
4个回答

walkor 打赏

location ~ "^/app/[a-zA-Z0-9_-]{16,32}$"
改成
location ^~ /app/bbaa660689dc6546f237056ac495af3e 试下

破建站的
location ^~ / {
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    if (!-f $request_filename){
        proxy_pass http://webman;
    }
}
location ^~ /app/bbaa660689dc6546f237056ac495af3e
{
    proxy_pass http://127.0.0.1:8796;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header X-Real-IP $remote_addr;
}

截图

  • 暂无评论
kof21411

有没有是域名的问题,域名有没有做cdn?

破建站的
[
    'enable'       => true,
    'websocket'    => 'websocket://0.0.0.0:8788',
    'api'          => 'http://0.0.0.0:3232',
    'app_key'      => 'b29cddbecf88bae109698855d5d52b3a',
    'app_secret'   => '309015f9348a53422523764e095a8bdd',
    'channel_hook' => 'http://127.0.0.1:8787/plugin/webman/push/hook',
    'auth'         => '/plugin/webman/push/auth'
]

            var connection = new Push({
                url: 'ws://' + '127.0.0.1:8788',
                app_key: 'b29cddbecf88bae109698855d5d52b3a',
                auth: '/plugin/webman/push/auth' // 订阅鉴权(仅限于私有频道)
            });

            var private_channel = connection.subscribe('private-admin-channel')

            private_channel.on('message', function (data) {
                console.log(data)
            });

截图

  • 暂无评论
🔝