-
Notifications
You must be signed in to change notification settings - Fork 662
Laravel websockets connection failed on production server #814
-
I've got a Laravel 8 API project along with a Nuxt JS front-end that uses Laravel Echo. I'm installed the Laravel Websockets server and have everything working just fine with the Pusher replacement config:
'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' => 6001,
'scheme' => 'http'
],
],
It's also worth noting here that I've also tried:
'options' => [
...
'port' => 6001,
'scheme' => 'https'
],
and...
'options' => [
...
'port' => 443,
'scheme' => 'https'
],
However, when I deploy to my CentOS 8 server and start the websockets server with php artisan websockets:serve (I'm in debug mode) and I try to connect, I'm getting a connection failed error. I'm using the default port of 6001 and default host of 0.0.0.0, the error I get from my front-end is:
WebSocket connection to 'wss://127.0.0.1/app/local?protocol=7&client=js&version=7.0.3&flash=false' failed:
My front-end is for example: https://example-gui.example.com/ whilst my running API is on https://example-api.example.com/, both on the same server, and the same server as the running websockets server.
I'm using Cloudflare for HTTPs, and I'm not sure whether I need to change anything with the host?
I originally had the connection like this:
'wss://127.0.0.1/app/local?protocol=7&client=js&version=7.0.3&flash=false', when I run
netstat -tulnpI do indeed see that port6001is in there.
What am I missing to connect in production?
I'm stuck in knowing how to get it to connect!
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments 6 replies
-
I have a smilar issue, but what's weird is it's been working just fine for months. Until we upgraded to PHP 8 yesterday, it just stopped, and am now getting a similar error with an empty exception message, re-thrown from PusherBroadcaster.php.
WebSocket connection to 'wss://api.domain.co:6001/app/UNIQUE_APP_IDENTIFIER?protocol=7&client=js&version=7.0.3&flash=false' failed:
This error is thrown from both my frontend, as well as the dashboard.
My setup uses SSL, and the user (as defined in supervisor) has read access to the fullchain cert and private key. As part of debugging, I even tried running it in debug mode as root, but the error persists. Nothing in the logs.
I've tinkered with SSL verification, on and off, but nothing makes a difference, even afterflushing config caches, restarting processes, etc.
This could still well be an environment issue, but I just don't know what it could be, as everything is setup correctly, and it worked perfectly before the upgrade.
Running Laravel 8.55, websockets 1.12 and pusher-http-php 5.0.3. My local ocnfiguration works fine, though it is of course in a Valet environment, and so it is configured slightly differently.
Beta Was this translation helpful? Give feedback.
All reactions
-
My configuration is as follows:
broadcasting:
[ 'driver' => 'pusher', 'key' => env('WEBSOCKETS_APP_KEY'), 'secret' => env('WEBSOCKETS_APP_SECRET'), 'app_id' => env('WEBSOCKETS_APP_ID'), 'options' => [ 'cluster' => env('WEBSOCKETS_APP_CLUSTER'), // resolves to mt1 'encrypted' => true, // have not tried false here yet 'host' => env('WEBSOCKETS_APP_HOST', array_values(array_filter(explode('/', env('APP_URL'))))[1]), 'port' => 6001, 'scheme' => 'https', 'curl_options' => [ CURLOPT_SSL_VERIFYHOST => (int) env('WEBSOCKETS_CURLOPT_SSL_VERIFYHOST', 2), // also tried 0 CURLOPT_SSL_VERIFYPEER => (int) env('WEBSOCKETS_CURLOPT_SSL_VERIFYPEER', 1), // also tried 0 ] ], ],
websockets:
'ssl' => [ 'local_cert' => env('WEBSOCKETS_SSL_LOCAL_CERT', null), // readable 'local_pk' => env('WEBSOCKETS_SSL_LOCAL_PK', null), // readable 'passphrase' => env('WEBSOCKETS_SSL_PASSPHRASE', null), 'verify_peer' => env('WEBSOCKETS_SSL_VERIFY_PEER', true), // also tried false ]
No need for me to share frontend code here, as the dashboard also does not connect, throwing the same "Pusher error: .".
Beta Was this translation helpful? Give feedback.
All reactions
-
My issue has been resolved. Turns out that the SSL certificates were moved due to a change in HTTP servers, which meant that the socket server was pointing to the incorrect symlinks.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
I also same isuue pusher.js?dc8e:4027 WebSocket connection to 'wss://127.0.0.1/app/AnyKey?protocol=7&client=js&version=7.0.6&flash=false' failed:
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2
-
You find a solution?
Beta Was this translation helpful? Give feedback.
All reactions
-
did you complete the server-side configuration?
see the reference doc for server-side configuration,
https://beyondco.de/docs/laravel-websockets/basic-usage/starting
https://beyondco.de/docs/laravel-websockets/basic-usage/ssl#usage-with-a-reverse-proxy-like-nginx
Beta Was this translation helpful? Give feedback.
All reactions
-
I was also facing the same issue. After contacting with hosting provider I found that my port 6001 was blocked in shared hosting. So that's why the laravel web socket is not working. Please check once if it's the same issue on your end also.
Beta Was this translation helpful? Give feedback.
All reactions
-
I was also facing the same issue. After contacting with hosting provider I found that my port 6001 was blocked in shared hosting. So that's why the laravel web socket is not working. Please check once if it's the same issue on your end also.
What port are you running?
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.