我正在使用此Laravel websockets package来拥有自己的websocket服务器。
如package documentation中所述,我具有以下配置:
.env设置:
PUSHER_APP_ID=761772
PUSHER_APP_KEY=qwerty
PUSHER_APP_SECRET=secret
PUSHER_APP_CLUSTER=ap2
broadcasting.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
],
],
websockets.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
中使用letencrypt,这是我在SSL
配置中的 websockets.php
部分:
'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
管理面板说:
频道当前状态不可用
和控制台说:
Firefox无法通过wss://myDomain.ir:6001 / app / qwerty?protocol = 7&client = js&version = 4.3.1&flash = false建立与服务器的连接。
pusher.min.js:8:6335 页面加载时,与wss://myDomain.ir:6001 / app / qwerty?protocol = 7&client = js&version = 4.3.1&flash = false的连接被中断。
有人知道我的问题是什么,我应该如何解决?
答案 0 :(得分:1)
我遇到了同样的问题,问题是对local_cert和local_pk的读取访问。
如果这是问题,您可以使用sudo php artisan websocket:serve
来尝试。
在这种情况下,请添加对文件的读取访问权限,或在/etc/supervisor/conf.d/websockets.conf中使用具有访问权限的用户
答案 1 :(得分:0)
我遇到了同样的问题,我使用的是Homestead,如果您使用的是Homestead,则应该使用超级用户(基于Debian的用户)或超级用户(基于RedHat的用户)的操作系统来运行laravel套接字,而无需手动输入命令“ php artisan websockets:serve”。
对于SSL,我还遵循以下文档提供了代客服务:https://docs.beyondco.de/laravel-websockets/1.0/basic-usage/ssl.html#usage-with-laravel-valet
答案 2 :(得分:0)
我遇到了同样的问题,首先您必须确保您尝试运行的端口是否打开。如果您在共享主机上运行套接字服务器,那么这是不可能的,或者您可以与客户支持交谈,他们将为您打开端口。如果您有 vps 或专用服务器,则可以从控制面板打开端口。首先尝试在没有 ssl 的情况下运行,如果它运行良好,则意味着您的端口已打开,然后配置您的 ssl 配置。
答案 3 :(得分:0)
如果您使用的是 Laravel < 8.0,请尝试 composer require pusher/pusher-php-server ^4.1
。