【问题标题】:Why Laravel Pusher is not working in server为什么 Laravel Pusher 在服务器中不起作用
【发布时间】:2020-12-27 10:43:07
【问题描述】:

我在我的 Web 应用程序中使用 Pusher。我的后端是用 Laravel 构建的,前端是用 Angular 10 构建的。一切都在我的本地机器上运行良好。但是在服务器中它不起作用。客户端连接失败,提示以下错误:

Pusher :  : [{"type":"WebSocketError","error":{"type":"PusherError","data":{"code":4001,"message":"Could not find app key `4895a6a5e4626a3afdfb`."}}}]

在我的本地机器上,一切正常。在 angular 和 laravel 项目中,我都使用相同的应用程序密钥。并且密钥是从推送者网站正确收集的。

这是我的客户端连接代码:

constructor() {
    console.log(window.location.hostname);
    this.pusher = new Pusher(environment.pusher.key, {
      cluster: environment.pusher.cluster,
      wsHost: '162.214.125.121',
      // wsHost: '127.0.0.1',
      wsPort: 6001,
      encrypted: false,
      forceTLS: false,
    });
    this.channel = this.pusher.subscribe('draw_options');
    Pusher.log = (msg) => {
      console.log(msg);
    };
  }
export const environment = {
  production: false,
  pusher: {
    key: '4895a6a5e4626a3afdfb',
    cluster: 'mt1',
  }
};

在我的 laravel 环境中:

PUSHER_APP_ID=1069575
PUSHER_APP_KEY=4895a6a5e4626a3afdfb
PUSHER_APP_SECRET=__its_correct_as_well__
PUSHER_APP_CLUSTER=mt1

在我的 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' => false,
                'encrypted' => false,
//                'host' => '162.214.125.121',
                'host' => '127.0.0.1',
                'port' => 6001,
                'scheme' => 'http'
            ],
        ],

在本地机器上一切正常。但是在服务器中这失败了 如果您转到以下网址,您会看到,socket 正在通过 laravel 连接。 http://api.etakweet.com/laravel-websockets

我也注意到,当事件被 laravel 项目广播时,没有找到日志。

【问题讨论】:

    标签: php angular laravel pusher laravel-websockets


    【解决方案1】:

    通过运行以下命令管理连接。

    php artisan config:clear
    

    【讨论】:

      猜你喜欢
      • 2020-05-20
      • 2012-10-10
      • 2019-10-28
      • 2013-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-17
      • 2013-12-28
      相关资源
      最近更新 更多