在我的本地机器广播中,它工作正常,但在生产中(数字海洋应用程序平台)它无法连接到服务器。
.env
BROADCAST_DRIVER=reverb
REVERB_APP_ID=my-app-id
REVERB_APP_KEY=my-app-key
REVERB_APP_SECRET=my-app-secret
REVERB_HOST=0.0.0.0 # Bind to all interfaces
REVERB_SCHEME=https # Use https for security, especially since your app is hosted publicly
REVERB_PORT=6001 # Default port for WebSocket connections
广播.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', 'reverb'),
/*
|--------------------------------------------------------------------------
| 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' => [
'reverb' => [
'driver' => 'pusher', // Reverb mimics Pusher
'key' => env('REVERB_APP_KEY', 'some-random-key'),
'secret' => env('REVERB_APP_SECRET', 'some-random-secret'),
'app_id' => env('REVERB_APP_ID', 'some-app-id'),
'options' => [
'host' => env('REVERB_HOST', 'mydigitaloceanlink'), // Your actual domain
'port' => env('REVERB_PORT', 443), // Port for WSS
'scheme' => env('REVERB_SCHEME', 'https'), // Secure WebSocket
'useTLS' => env('REVERB_SCHEME', 'https') === 'https', // Match TLS to scheme
'encrypted' => true, // Ensure connection encryption
],
],
'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' => env('REVERB_SCHEME') === 'https',
],
],
'ably' => [
'driver' => 'ably',
'key' => env('ABLY_KEY'),
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
'log' => [
'driver' => 'log',
],
'null' => [
'driver' => 'null',
],
],
];
混响.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Reverb Server
|--------------------------------------------------------------------------
|
| This option controls the default server used by Reverb to handle
| incoming messages as well as broadcasting message to all your
| connected clients. At this time only "reverb" is supported.
|
*/
'default' => env('REVERB_SERVER', 'reverb'),
/*
|--------------------------------------------------------------------------
| Reverb Servers
|--------------------------------------------------------------------------
|
| Here you may define details for each of the supported Reverb servers.
| Each server has its own configuration options that are defined in
| the array below. You should ensure all the options are present.
|
*/
'servers' => [
'reverb' => [
'host' => env('REVERB_HOST', '0.0.0.0'),
'port' => env('REVERB_PORT', 9000),
'hostname' => env('REVERB_HOST'),
'options' => [
'tls' => [],
],
'max_request_size' => env('REVERB_MAX_REQUEST_SIZE', 10_000),
'scaling' => [
'enabled' => env('REVERB_SCALING_ENABLED', false),
'channel' => env('REVERB_SCALING_CHANNEL', 'reverb'),
'server' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'port' => env('REDIS_PORT', '6379'),
'username' => env('REDIS_USERNAME'),
'password' => env('REDIS_PASSWORD'),
'database' => env('REDIS_DB', '0'),
],
],
'pulse_ingest_interval' => env('REVERB_PULSE_INGEST_INTERVAL', 15),
'telescope_ingest_interval' => env('REVERB_TELESCOPE_INGEST_INTERVAL', 15),
],
],
/*
|--------------------------------------------------------------------------
| Reverb Applications
|--------------------------------------------------------------------------
|
| Here you may define how Reverb applications are managed. If you choose
| to use the "config" provider, you may define an array of apps which
| your server will support, including their connection credentials.
|
*/
'apps' => [
'provider' => 'config',
'apps' => [
[
'key' => env('REVERB_APP_KEY'),
'secret' => env('REVERB_APP_SECRET'),
'app_id' => env('REVERB_APP_ID'),
'options' => [
'host' => env('REVERB_HOST'),
'port' => env('REVERB_PORT', 443),
'scheme' => env('REVERB_SCHEME', 'https'),
'useTLS' => env('REVERB_SCHEME') === 'https', // Enable TLS for HTTPS
],
'allowed_origins' => ['*'],
'ping_interval' => env('REVERB_APP_PING_INTERVAL', 60),
'activity_timeout' => env('REVERB_APP_ACTIVITY_TIMEOUT', 30),
'max_message_size' => env('REVERB_APP_MAX_MESSAGE_SIZE', 10_000),
],
],
],
];
在我的控制器中我尝试广播这个
broadcast(new FileUploaded($user->id, $file->getClientOriginalName(), $counter, $asset->id));
} catch (\Exception $e) {
// Log detailed error information
Log::error('Error broadcasting FileUploaded event:', [
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString(),
]);
}
我收到以下错误:
Local. ERROR: Error broadcasting FileUploaded event: ("message": "Pusher error: CURL error 7: Failed to connect to 0.0.0.0 port 6001 after 6 ms: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://0.0.0.0/apps/my-app-id/events?auth_key=my-app-key&auth_timestamp=1727691940&auth_version=1.0&body_md5=bdfd3fdcc3c19ab647114c8d4ca230e2&auth_signature=cd729c19fa4d846b99f424b7a856584445272f695ffe9ff26cc786@fe0e39a71.", "file": "/workspace/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php", "line": 164, "trace": "#0 /workspace/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastEvent.php(92): Illuminate\Broadcasting\Broadcasters\PusherBroadcaster->broadcast()")
端口 443 和端口 8080 也发生同样的情况,我收到 ssl 错误,这是可以理解的。在控制台中,当我运行启动服务器时,它正在启动。
php artisan reverb:start --debug
INFO Starting server on 0.0.0.0:6001.
Pruning Stale Connections .......................................................................................
Pinging Inactive Connections
从邮递员那里我尝试了 wss 连接,但它被束缚了。我现在已经没有选择了。
我也遇到同样的情况,还是找不到解决办法哈哈...