本地websockets运行起来很有魅力,但在生产环境中,我不断得到标题中的错误。
我使用WebSocket包的一些背景信息:beyondcode/laravel-websockets.我正在使用supervisor运行'php artisan websockets:serve --port=6004'。我还确保端口6004是打开的。
在生产中,我尝试了使用和不使用SSL的设置,都给出了标题中的错误。
SSL设置:
我的回声设置:
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
wsHost: window.location.hostname,
wsPort: 6004,
wssPort: 6004,
disableStats: true,
enabledTransports: ['ws', 'wss'],
});
我的推流器设置:
'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' => '127.0.0.1',
'port' => 6004,
'scheme' => 'https',
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
],
],
我的websockets设置:
'apps' => [
[
'id' => env('PUSHER_APP_ID'),
'name' => env('APP_NAME'),
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'enable_client_messages' => true,
'enable_statistics' => true,
],
],
'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' => base_path().'/ssl/server.crt',
/*
* Path to local private key file on filesystem in case of separate files for
* certificate (local_cert) and private key.
*/
'local_pk' => base_path().'/ssl/server.pem',
/*
* Passphrase for your local_cert file.
*/
'passphrase' => null,
'verify_peer' => false,
],
无SSL设置:
我的回声设置:
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
wsHost: window.location.hostname,
wsPort: 6004,
disableStats: true,
enabledTransports: ['ws', 'wss'],
});
我的推流器设置:
'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' => false,
'host' => '127.0.0.1',
'port' => 6004,
'scheme' => 'http',
],
],
我的websockets设置:
'apps' => [
[
'id' => env('PUSHER_APP_ID'),
'name' => env('APP_NAME'),
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'enable_client_messages' => true,
'enable_statistics' => true,
],
],
'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,
/*
* Path to local private key file on filesystem in case of separate files for
* certificate (local_cert) and private key.
*/
'local_pk' => null,
/*
* Passphrase for your local_cert file.
*/
'passphrase' => null,
],
7条答案
按热度按时间hzbexzde1#
在我的情况下后降级推动者从6东西到
它开始起作用了我爱你!😠
ruoxqz4g2#
所以经过几天的战斗与ssl,我必须与我的知识分享在这个主题。根据docs安装后,websockets可以使用http,但不能使用ssl(443)。我想我有一个问题与正确的设置和路径.pem(让我们加密)(我尝试了一切,这对我的工作).我在VPS服务器上使用Apatche2mydomain.conf的普通设置,端口 *:443。
websockets.php:
broadcasting.php:
bootstrap.js:
我希望这会有所帮助。谢谢你,祝你好运,很快就能见到你:)
ha5z0ras3#
我也遇到了这个问题,并发布了一个更详细的问题,我向您展示了防火墙,laravel,nuxt,nginx和websockets的设置。几天后,找到了一个解决方案:Laravel + Nuxt + Nginx: WebSocket is closed before the connection is established
For comparison, see also the question itself on the link above.
项目设置
防火墙
netstat -ntlp| grep LISTEN
lsof -i -P -n| grep LISTEN
ufw状态
ufw秀收听
Laravel
vim /var/www/API/config/websockets.php
vim /var/www/API/config/broadcasting.php
Nuxt
vim /var/www/client/package.json
vim /var/www/client/plugins/echo.js
Nginx
vim /etc/nginx/nginx.conf文件
vim /etc/nginx/sites-available/larastart.sitewww.example.com
omvjsjqw4#
我在我的实时服务器上也遇到了这个问题。对我来说,它不工作,因为我的端口不允许。
sudo ufw allow 6001
后,把这个命令我的活服务器开始工作. enter image description herepu82cl6c5#
通过在websockets.php中添加ssl路径修复了此问题。我使用购买的SSL,我在Plesk中添加。在CLI中,证书的路径来自root:cd /usr/local/psa/var/certificates然后我做了'ls'来检查证书名称。在我的例子中,我使用了带有私钥的证书,并在config/websockets.php中添加了local_cert路径和local_pk路径
最终设置:
websockets.php
广播.php
bootstrap.js
顺便说一句,当你在bootstrap.js中更改一些东西时,不要忘记运行npm run dev,我在端口6004上运行它,所以如果你在6001上运行它,不要忘记更改我上面的设置
zqry0prt6#
你试过在“窗口.回声”中使用这些选项吗?
vmdwslir7#
更新2023与laravel 10,vue 3,pusher-js 7.6
把这个configs和你是好去:
bootstrap.js内部:
inside broadcasting.php
内部环境