Laravel Websockets not working with Https worked fine without ssl configuration tried every thing found in the documnetion link https://beyondco.de/docs/laravel-websockets/basic-usage/ssl but nothing has worked
Here my websockets configurations
brodcasting.php
'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' => 6001,
'scheme' => 'http',
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
],
],
bootstrap.js
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
wsHost: window.location.hostname,
wsPort: 6001,
forceTLS: false,
disableStats: true,
enabledTransports: ['ws','wss'],
authorizer: (channel, options) => {
return {
authorize: (socketId, callback) => {
axios.post('/api/broadcasting/auth', {
socket_id: socketId,
channel_name: channel.name
}).then(({data}) => {
callback(false, data);
}).catch(error => {
callback(true, error);
});
}
};
}
});
.env
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT=/etc/letsencrypt/live/xxxxxxxx/fullchain.pem
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK=/etc/letsencrypt/live/xxxxxxxxxx/privkey.pem
websockets.php
'ssl' => [
'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
'capath' => env('LARAVEL_WEBSOCKETS_SSL_CA', null),
'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', ''),
'verify_peer' => env('APP_ENV') === 'production',
'allow_self_signed' => env('APP_ENV') !== 'production',
],
I have found the solutions for Me the isssue was with LetsEncrypt ssl made some changes in
added in default.conf in sites-available
# Added this for Web Sockets Proxy
location /ws/ {
proxy_pass http://127.0.0.1:6001;
proxy_set_header Host $host;
proxy_read_timeout 60;
proxy_connect_timeout 60;
proxy_redirect off;
# Allow the use of websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
in supervior changed the
user=root
commad=sudo /usr/bin/php /var/www/html/TestFolder/artisan websockets:serve
[program:websockets]
command=sudo /usr/bin/php /var/www/html/TestFolder/artisan websockets:serve
numprocs=1
autostart=true
autorestart=true
user=root
redirect_stderr=true
after
sudo supervisorctl update websockets
sudo supervisorctl restart all
it worked magically hope this helps!