laravel 无法连接

wpcxdonn  于 2023-01-27  发布在  其他
关注(0)|答案(5)|浏览(147)

我使用这个Laravel websockets package来拥有我自己的WebSocket服务器。
正如package documentation中提到的,我有这样的配置:

.env设置:

PUSHER_APP_ID=761772
PUSHER_APP_KEY=qwerty
PUSHER_APP_SECRET=secret
PUSHER_APP_CLUSTER=ap2

广播.php:

'pusher' => [
        'driver' => 'pusher',
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'app_id' => env('PUSHER_APP_ID'),
        'options' => [
            'cluster' => env('PUSHER_APP_CLUSTER'),
            'encrypted' => true,
            //'host' => '105.208.174.8', <--I did test this too
            'host' => '127.0.0.1',
            'port' => 6001,
            'scheme' => 'https'//<--Tested with http
        ],
    ],

网络套接字.php:

'apps' => [
    [
        'id' => env('PUSHER_APP_ID'),
        'name' => env('APP_NAME'),
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'enable_client_messages' => false,
        'enable_statistics' => true,
    ],
],

** Bootstrap .js:**

/**
 * Echo exposes an expressive API for subscribing to channels and listening
 * for events that are broadcast by Laravel. Echo and event broadcasting
 * allows your team to easily build robust real-time web applications.
 */

import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'qwerty',
    wsHost: window.location.hostname,
    wsPort: 6001,
    disableStats: true,
    encrypted: true,
    enabledTransports: ['ws', 'wss'] //This was added from issue 86

});

This is issue number 86 in package repository
我在directadmin control panel中使用letsencrypt,这是websockets.php配置的 * SSL * 部分:

'ssl' => [
    /*
     * Path to local certificate file on filesystem. It must be a PEM encoded file which
     * contains your certificate and private key. It can optionally contain the
     * certificate chain of issuers. The private key also may be contained
     * in a separate file specified by local_pk.
     */
    //'local_cert' => null,
    'local_cert' => '/home/myDomain/domains/myDomain/public_html/vendor/react/socket/examples/localhost.pem',
      //'local_cert' => '/usr/local/directadmin/data/users/myDomain/domains/myDomain.ir.cert',
    /*
     * Path to local private key file on filesystem in case of separate files for
     * certificate (local_cert) and private key.
     */
    //'local_pk' => null,
    'local_pk' => '/usr/local/directadmin/data/users/myDomain/domains/myDomain.ir.key',

    /*
     * Passphrase for your local_cert file.
     */
    'passphrase' => null,
    ],

但当我使用php artisan websockets:serve时,似乎连接有问题,myDomain.com/laravel-websockets管理面板显示:
通道的当前状态不可用
控制台显示:
火狐浏览器无法建立与服务器wss://myDomain.ir:6001/app/qwerty?protocol=7&client=js&version=4.3.1&flash=false。
您myDomain.ir:6001/app/qwerty?protocol=7&client=js&version=4.3.1&flash=false:页面正在加载中
有人知道我的问题是什么吗?我应该如何解决这个问题?

2g32fytz

2g32fytz1#

我遇到了同样的问题,问题是local_certlocal_pk的读访问权限。
您可以使用sudo php artisan websocket:serve来尝试是否存在此问题。
如果是这种情况,请在/etc/supervisor/conf.d/websockets.conf中添加对文件的读访问权限或使用具有该访问权限的用户

tvmytwxo

tvmytwxo2#

我也遇到了同样的问题,我在使用宅基地,你在Homestead吗,如果是这样的话,你应该使用Supervisor(基于Debian)或Supervisord(基于REDHat)操作系统来运行laravel套接字,而不必手动输入命令“php artisan websockets:serve”。
您可以参考此文档。https://docs.beyondco.de/laravel-websockets/1.0/basic-usage/starting.html#restricting-the-listening-host
对于SSL,我也遵循了Valet的文档:https://docs.beyondco.de/laravel-websockets/1.0/basic-usage/ssl.html#usage-with-laravel-valet

xqk2d5yq

xqk2d5yq3#

我有同样的问题,首先你必须确保端口,你试图运行是开放的或没有。如果你正在运行套接字服务器上的共享主机,那么它是不可能的,或者你可以与客户支持,他们会为你打开端口。如果你有vps或专用服务器,你可以从你的控制面板打开端口。首先尝试运行没有ssl如果它运行良好,这意味着你的端口是开放的,然后配置你的ssl配置。

vdzxcuhz

vdzxcuhz4#

如果您使用的Laravel〈8.0,请尝试composer require pusher/pusher-php-server ^4.1

jgovgodb

jgovgodb5#

也许你没有运行服务器

*php工匠网络套接字:服务

相关问题