HTTPS本地服务器上的Laravel WebSocket

2w3rbyxf  于 2023-05-17  发布在  其他
关注(0)|答案(1)|浏览(159)

我正在尝试用websocket实现一个本地网络可访问的laravel应用程序。
一切都在http上运行良好,现在我们需要升级到https以允许windows桌面上的应用程序通知。
我做了一个自签名证书使用openssl命令,我发现在网上。
我设法使应用程序在https上工作,但不是它的websocket。我做了laravel websocket文档中的每一个说明,但都无济于事。
服务器设置:Windows + XAMPP

    • 广播. 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"

我还在system32上将127.0.0.1设置为lqs.miso
我得到连接失败,没有其他错误提示.

svdrlsy4

svdrlsy41#

当我从http切换到https时,我在服务器上遇到了同样的错误,将'verify_peer' => false,添加到config/websockets.php中的'ssl'密钥为我修复了它。
例如:

'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,
    ],

相关问题