I have a problem with laravel-websockets which is not connecting to port 6001 or others. The port number is simply not passed in the request. The page https://website.com/laravel-websockets working fine with a properly passed port in the request. My workspace is Forge + Digital Ocean, domain added to DO, ssl cert Let's Encrypt generated through the Forge
I've tried many different configurations, with different domain and subdomains, different servers (droplets), different ports and different SSL (Cloudflare generated SSL too). I've also tried different versions for the packages, but the final result is the same.
use:
"laravel/framework": "^9.2",
"pusher/pusher-php-server": "^7.0",
"beyondcode/laravel-websockets": "^1.13",
"laravel-echo": "^1.11.7",
"pusher-js": "^7.0.6"
broadcasting.php
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'https',
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
],
websockets.php
'ssl' => [
'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),
'verify_peer' => false,
],
bootstrap.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,
wssPort: 6001,
disableStats: true,
enabledTransports: ['ws', 'wss'],
});
.env
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT=/etc/nginx/ssl/domain.name/1111111/server.crt
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK=/etc/nginx/ssl/domain.name/1111111/server.key
Nginx conf
map $http_upgrade $type {
default "web";
websocket "ws";
}
location / {
try_files /nonexistent @$type;
}
location @web {
try_files $uri $uri/ /index.php?$query_string;
}
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;
}
Problem,
this screen from uri laravel-webscokets this screen from other page