laravelsslwebsockethttpslaravel-websockets

Laravel websocket on https local server


I'm trying to implement a local network-accessible laravel app with websocket.

Everything works well on http, now we need to upgrade to https to allow the app on windows desktop notification.

I made a self-signed certificate using openssl command I found on the net.

I manage to make the app work on https but not its websocket. I did every instructions in the laravel websocket documentation but no to avail.

Server setup: Windows+XAMPP

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'),
            'host' => 'lqs.miso',
            'port' => 6001,
            'scheme' => 'https'
        ],
    ],

bootstrap.js

import Echo from "laravel-echo"

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'ABCDEFG',
    wsHost: window.location.hostname,
    wsPort: 6001,
    wssPort: 6001,
    forceTLS: true,
    disableStats: true,
    enabledTransports: ['ws', 'wss']
});

.env

LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT="C:/xampp/crt/lqs.miso/server.crt"
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK="C:/xampp/crt/lqs.miso/server.key"

I also set 127.0.0.1 to lqs.miso on system32

I'm getting connection failed with no other hints of error.


Solution

  • i was getting same error on server when i switched from http to https, adding 'verify_peer' => false, to config/websockets.php inside 'ssl' key fixed it for me.

    for example:

    
    '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' => env('LARAVEL_WEBSOCKETS_SSL_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' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
    
            /*
             * Passphrase for your local_cert file.
             */
            'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),
            'verify_peer' => false,
        ],