[英]Laravel websockets AWS EC2 - Connection failed
I'm using laravel-websockets and is working like a charm in my local docker machine but I can't seem to make it work when I deploy it in the AWS EC2 machine.我正在使用 laravel-websockets 并且在我的本地 docker 机器上工作得很好,但是当我将它部署在 AWS EC2 机器上时,我似乎无法让它工作。
This is the error message I get:这是我收到的错误消息:
pusher.min.js:8 WebSocket connection to
'wss://sample.project:6001/app/b0901feacd04936e?protocol=7&client=js&version=4.3.1&flash=false' failed:
These are my config files:这些是我的配置文件:
broadcasting.php广播.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'),
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'http',
],
],
websockets.php 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引导程序.js
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
wsHost: window.location.hostname,
wsPort: 6001,
forceTLS: false,
disableStats: true,
});
I've opened 6001 port in my security group:我在我的安全组中打开了 6001 端口:
But I can't make it work.但我不能让它工作。 I've tried a lot of the fixes in other SO questions but none worked, am I missing something?我在其他 SO 问题中尝试了很多修复,但都没有奏效,我错过了什么吗? In desperate need of help here.这里急需帮助。
Thank you very much.非常感谢。
Your SSL settings in config/websockets.php
should indicate they require two variables fron the .env
file.您在config/websockets.php
中的 SSL 设置应该表明它们需要.env
文件中的两个变量。
'ssl' => [
'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
'passphrase' => null,
'verify_peer' => false,
],
Then over in your .env
file, for local (in Valet) specify your test site's certs, ie:然后在您的.env
文件中,为本地(在 Valet 中)指定您的测试站点的证书,即:
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT="/users/grant/.config/valet/Certificates/localsite.test.crt"
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK="/users/grant/.config/valet/Certificates/localsite.test.key"
Alternatively, if it's on your Production environment, point it to your production SSL CRT & key:或者,如果它在您的生产环境中,请将其指向您的生产 SSL CRT 和密钥:
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT="/etc/nginx/ssl/yourprodsite.com/1231342/server.crt"
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK="/etc/nginx/ssl/yourprodsite.com/1231342/server.key"
Your bootstrap.js
(or similar) receiving JS end wouldn't really change - just ensure it matches what's in config/broadcasting.php
:您的bootstrap.js
(或类似的)接收 JS 端不会真正改变 - 只需确保它与config/broadcasting.php
中的内容匹配:
import Echo from 'laravel-echo';
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'yoursite-pusher-key',
wsHost: window.location.hostname,
wsPort: 6001,
wssPort: 6001,
disableStats: true,
});
Config counterpart config/broadcasting.php
inside of the connections
array:在connections
数组中配置对应的config/broadcasting.php
:
'pusher' => [
'driver' => 'pusher',
'key' => 'yoursite-pusher-key',
'secret' => 'yoursite-secret',
'app_id' => 'yoursite',
'options' => [
'cluster' => 'main-cluster',
'encrypted' => true,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'https',
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
],
],
Personally I could not get my setup to work without SSL & had to provide the SSL certificates accurately.就个人而言,如果没有 SSL,我无法让我的设置正常工作,并且必须准确地提供 SSL 证书。 Don't forget to use valet secure
locally, if using Valet.如果使用 Valet,请不要忘记在本地使用valet secure
。
You can have a look here for more info regarding SSL.您可以在此处查看有关 SSL 的更多信息。
Once you serve the Websockets using php artisan websockets:serve
it's OK if it seems like it's stalling, navigate over to the frontend & hard refresh (CMD+SHIFT+R) or Win (CTRL+F5) and hopefully the connection will be established.使用php artisan websockets:serve
服务 Websockets 后,如果它似乎停止运行,就可以了,导航到前端和硬刷新 (CMD+SHIFT+R) 或 Win (CTRL+F5) 并希望建立连接。
Ensure you are using latest libraries and if you have set up your JavaScript init scripts inside of a bootstrap you may need to run npm run dev
or similar to compile assets.确保您使用的是最新的库,并且如果您在引导程序中设置了 JavaScript 初始化脚本,您可能需要运行npm run dev
或类似的工具来编译资产。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.