我使用这个Laravel websocket包来拥有自己的websocket服务器。
正如在包留档中提到的,我有这样的配置:
。环境
设置:
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,
],
],
独自创立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
});
这是包存储库中的86号问题
我将letsencrypt与我的directadmin控制面板一起使用,这是我的
SSL
部分WebSocket。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:service
时,连接和myDomain似乎有问题。com/laravel websockets
管理面板显示:
频道的当前状态不可用
控制台上说:
Firefox无法在上建立与服务器的连接wss://myDomain.ir:6001/app/qwerty?protocol=7
pusher.min.js: 8:6335连接到wss://myDomain.ir:6001/app/qwerty?protocol=7
有人知道我的问题是什么吗?我应该如何解决?
我也有同样的问题,问题是local\u cert
和local\u pk
的读取权限。
您可以使用sudo php artisan web套接字:服务
来尝试这是否是问题。
如果是这样,请添加对文件的读取访问权限,或者使用具有/etc/主管/conf. d/websockets.conf
中的访问权限的用户
我也有同样的问题,我在使用Homestead,你在Homestead上吗?如果是这样,你应该使用supervisor(基于Debian)或supervisord(基于REDHat)操作系统来运行laravel套接字,而无需随时手动输入命令“php artisan websockets:serve”。
您可以参考此文档。https://docs.beyondco.de/laravel-websockets/1.0/basic-usage/starting.html#restricting-倾听的主持人
对于SSL,我还与代客泊车员一起遵循了以下文档:https://docs.beyondco.de/laravel-websockets/1.0/basic-usage/ssl.html#usage-拉拉维尔贴身男仆
我有同样的问题,首先你必须确保你试图运行的端口是否打开。如果您在共享主机上运行socket server,则这是不可能的,或者您可以与客户支持人员联系,他们将为您打开端口。如果您有vps或专用服务器,您可以从控制面板打开端口。首先尝试在没有ssl的情况下运行,如果运行正常,则表示端口已打开,然后配置ssl配置。