Local websockets is running like a charm but on production I keep getting the error in the title.
Some background information I'm using the websocket package: beyondcode/laravel-websockets. I'm running 'php artisan websockets:serve --port=6004' with supervisor. I also made sure port 6004 is open.
In production I tried the settings with and without SSL both gave the error in the title.
My echo settings:
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'],
});
My pusher settings:
'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,
]
],
],
My websockets settings:
'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,
],
My echo settings:
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
wsHost: window.location.hostname,
wsPort: 6004,
disableStats: true,
enabledTransports: ['ws', 'wss'],
});
My pusher settings:
'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',
],
],
My websockets settings:
'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,
],
In my case after downgrading pusher from 6 something to
"pusher-js": "^4.3.1"
it started to work. Javascript I love you! ðŸ˜
so after a few days of fighting with ssl, I have to share with my knowledge in this topic.. After installation according to docs, websockets was worked with http, but not after using ssl(443). I think I had a problem with the correct settings and path to .pem (Let's Encrypt)(I tried everything, this work for me). I use normal settings for Apatche2 mydomain.conf with port*:443, on VPS server.
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' => true,
'enable_statistics' => true,
'encrypted' => true,
],
],
'ssl' => [
'local_cert' => '/etc/letsencrypt/live/server1.mydomain.com/fullchain.pem',
'local_pk' => '/etc/letsencrypt/live/server1.mydomain.com/privkey.pem',
'passphrase' => null,
'verify_peer' => false,
],
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' => 'server1.mydomain.com',
'port' => 6001,
'scheme' => 'https',
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
],
],
bootstrap.js:
window.Echo = new Echo({
auth:{ headers: { 'Authorization': 'Bearer ' + user.token } },
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
wsHost: window.location.hostname,
wsPort: 6001,
wssPort: 6001,
disableStats: false,
enabledTransports: ['ws', 'wss']
});
I hope this will be helpful. thank you, good luck and see you soon:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With