I must be missing something basic, but I can't get any version of Chrome to connect to my Laravel Websockets server. I have a server running with Let's Encrypt SSL and everything works fine on Firefox and Safari, but I can't get Chrome to connect no matter what I try. I've tried from both Windows and Macs, and from Incognito mode on both. Here is the error I get in Chrome Dev Tools (domain name obfuscated):
app.js:59203 WebSocket connection to 'wss://socket.domain.tld:6001/app/jdisalaufoesa8?protocol=7&client=js&version=4.3.1&flash=false' failed: WebSocket opening handshake was canceled
createWebSocket @ app.js:59203
getSocket @ app.js:60113
TransportConnection.connect @ app.js:60254
onInitialized @ app.js:67187
Dispatcher.emit @ app.js:60419
TransportConnection.changeState @ app.js:60362
default_1 @ app.js:60646
TransportStrategy.connect @ app.js:67216
SequentialStrategy.tryStrategy @ app.js:67330
tryNextStrategy @ app.js:67301
(anonymous) @ app.js:67327
(anonymous) @ app.js:59792
(anonymous) @ app.js:59823
Here is my Echo setup:
import Echo from "laravel-echo";
window.Pusher = require("pusher-js");
window.Echo = new Echo({
broadcaster: "pusher",
key: process.env.MIX_PUSHER_APP_KEY,
wsHost: "socket.domain.tld",
wsPort: 6001,
wssPort: 6001,
disableStats: true,
encrypted: true,
enabledTransports: ["ws", "wss"]
});
Events are firing from the server when I'm watching on the dashboard, and also when I have another window open to the same page on a different browser.
Server is Ubuntu 18.04.2
PHP 7.2
Using Supervisor to run the php artisan websockets:serve command.
That error (i.e. "WebSocket opening handshake was canceled") seems to point to an SSL issue. How are you configuring SSL? Does your certificate chain have the intermediate cert included (it should)?
I thought the same thing, but why would Chrome have issues, and not Firefox or Safari?
Anyhow, here is my ssl config in config/websockets.php:
'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' => '/etc/letsencrypt/live/socket.domain.tld/fullchain.pem',
/*
* Path to local private key file on filesystem in case of separate files for
* certificate (local_cert) and private key.
*/
'local_pk' => '/etc/letsencrypt/live/socket.domain.tld/privkey.pem',
/*
* Passphrase for your local_cert file.
*/
'passphrase' => null,
],
The www-data user has been given read access to both of the certs.
Using 'verify_peer' => false, in ssl config solved my issue.
@IamSwap I would very much recommend against doing that if possible. See my comment here: https://github.com/beyondcode/laravel-websockets/issues/109#issuecomment-480519225
@francislavoie Thanks for pointing that out!
But I am using it with the Laravel valet. I guess it should be ok to use in local development?
Yeah that would go under the "you trust that your network is completely private" bit. It's dangerous to turn off verification for any traffic going over public networks.
Yeah, I have 'verify_peer' => false, for Valet, but not for my staging server.
I've tried every combination of settings in the Echo config, but still can't get Chrome (of any version, including Canary) to connect.
Does Chrome not allow the websocket server and the application server to be different domain names? I wouldn't think so, since the Pusher service would always be a different domain.
Grasping at straws!
I'm going to close this issue. I set up a new server on Forge and everything is working fine. I can't figure out what happened with the Ubuntu server that I set up myself, everything should be the same.
We have reproduced this issue, also using a Let's Encrypt certificate, and filed a bug that can be followed here: https://crbug.com/993907
Granting www-data user read access to certificates and using 'verify_peer' => false, in SSL (websockets.php) helped me.
'verify_peer' => false, in websockets.php helped me on my live server.
Doing 'verify_peer' => false, and upgrading pusher/pusher-php-server to ~4.0 worked for me.
Most helpful comment
Using
'verify_peer' => false,in ssl config solved my issue.