【问题标题】:Check laravel websocket on server检查服务器上的 laravel websocket
【发布时间】:2021-07-16 08:19:05
【问题描述】:

我正在尝试实现 laravel websockets 并尝试访问仪表板。

http://127.0.0.1:8000/laravel-websockets 地址将我带到本地计算机上的仪表板,但是当我托管它并尝试www.mysite.com/laravel-websockets 时,它显示该页面不存在。 我使用 this 包用于 laravel websockets 和 AWS EC2 实例用于托管。

broadcasting.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Broadcaster
    |--------------------------------------------------------------------------
    |
    | This option controls the default broadcaster that will be used by the
    | framework when an event needs to be broadcast. You may set this to
    | any of the connections defined in the "connections" array below.
    |
    | Supported: "pusher", "ably", "redis", "log", "null"
    |
    */

    'default' => env('BROADCAST_DRIVER', 'null'),

    /*
    |--------------------------------------------------------------------------
    | Broadcast Connections
    |--------------------------------------------------------------------------
    |
    | Here you may define all of the broadcast connections that will be used
    | to broadcast events to other systems or over websockets. Samples of
    | each available type of connection are provided inside this array.
    |
    */

    'connections' => [

        '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,
                'host' => '127.0.0.1',
                'port' => 6001,
                'scheme' => 'http'
            ],
        ],

        'ably' => [
            'driver' => 'ably',
            'key' => env('ABLY_KEY'),
        ],

        'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
        ],

        'log' => [
            'driver' => 'log',
        ],

        'null' => [
            'driver' => 'null',
        ],

    ],

];

【问题讨论】:

    标签: php laravel amazon-web-services amazon-ec2 websocket


    【解决方案1】:

    默认情况下,仅当您的应用程序环境设置为本地时才允许访问 WebSocket 仪表板。

    但是,您可以通过覆盖正在使用的 Laravel Gate 来更改此行为。一个很好的地方是 Laravel 附带的 AuthServiceProvider。

    public function boot()
        {
            $this->registerPolicies();
    
            Gate::define('viewWebSocketsDashboard', function ($user = null) {
                return in_array($user->email, [
                   //
                ]);
            });
        }
    

    请参阅此文档https://beyondco.de/docs/laravel-websockets/debugging/dashboard#protecting-the-dashboard

    【讨论】:

      猜你喜欢
      • 2020-06-28
      • 1970-01-01
      • 1970-01-01
      • 2015-03-21
      • 1970-01-01
      • 1970-01-01
      • 2012-11-26
      • 2020-12-30
      • 2021-08-07
      相关资源
      最近更新 更多