【问题标题】:Laravel Websocket not working when deploying in production server - Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT在生产服务器中部署时 Laravel Websocket 不起作用 - 连接建立错误:net::ERR_CONNECTION_TIMED_OUT
【发布时间】:2020-05-10 06:30:26
【问题描述】:

我已经敲了几个小时的头,因为当我在生产服务器中部署我的 websockets 时,它不会工作。我一直有这个错误:Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT

这些是我的配置:

websockets.php

返回 [

/*
 * Set a custom dashboard configuration
 */
'dashboard' => [
    'port' => env('LARAVEL_WEBSOCKETS_PORT', 6002),
],

/*
 * This package comes with multi tenancy out of the box. Here you can
 * configure the different apps that can use the webSockets server.
 *
 * Optionally you specify capacity so you can limit the maximum
 * concurrent connections for a specific app.
 *
 * Optionally you can disable client events so clients cannot send
 * messages to each other via the webSockets.
 */
'apps' => [
    [
        'id' => env('PUSHER_APP_ID'),
        'name' => env('APP_NAME'),
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'path' => env('PUSHER_APP_PATH'),
        'capacity' => null,
        'enable_client_messages' => false,
        'enable_statistics' => true,
    ],
 '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,
],
],
....

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'),
//                'useTLS' => true, //live
//                'encrypted' => true, //comment out in local
                'host' => '127.0.0.1',
                'port' => 6002,
                'scheme' => 'https', //in live this is https
//                'scheme' => 'http' //in local this is only http,
                'curl_options' => [
                    CURLOPT_SSL_VERIFYHOST => 0,
                    CURLOPT_SLL_VERIFYPEER => 0
                ]
            ],
        ],

bootstrap.js

import Echo from 'laravel-echo';

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

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    forceTLS: true, //for live
    // encrypted: false, //local
    encrypted: true, //live
    wsHost: window.location.hostname,
    wsPort: 6002,
    wssPort: 6002, //in local, comment this one
    // enabledTransports: ['ws','wss'],
    disableStats: true
});

我不确定我在这里做错了什么,但看起来我已经按照互联网上的所有教程进行操作,但无济于事,我收到了那个错误。

谢谢。

【问题讨论】:

    标签: laravel websocket pusher laravel-echo


    【解决方案1】:

    抱歉,我可以通过打开我选择在服务器中使用的端口来解决这个问题,在我的例子中是端口6002。这对我来说是一个非常新手的错误,因为我在服务器方面并不是那么出色。

    这就是你打开端口How to open some ports on Ubuntu?的方式

    无论如何,谢谢!

    【讨论】:

      猜你喜欢
      • 2019-08-30
      • 2019-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-02
      • 2017-11-18
      • 2017-05-31
      相关资源
      最近更新 更多