laravel / reverb

Laravel Reverb provides a real-time WebSocket communication backend for Laravel applications.
https://reverb.laravel.com
MIT License
941 stars 63 forks source link

Reverb broadcasting of event is failing with pusher error. #223

Closed amit772000 closed 1 week ago

amit772000 commented 1 week ago

Reverb Version

beta

Laravel Version

10.48

PHP Version

8.2

Description

i have configured reverb with my sub domain abc.example.com. connection is established successfully but when broadcasting event it is ended up with pusher error as below.

Illuminate\Broadcasting\BroadcastException: Pusher error: <!DOCTYPE html>

Not Found ### Steps To Reproduce my .env BROADCAST_CONNECTION=reverb VITE_APP_NAME="${APP_NAME}" REVERB_SERVER_HOST=abc.example.com REVERB_SERVER_PORT=8080 REVERB_APP_ID=925352 REVERB_APP_KEY=jop6z2fyoet59fm7l3rm REVERB_APP_SECRET=tehjaek3gf748khyfcqxq REVERB_HOST="abc.example.com" REVERB_PORT=443 REVERB_SCHEME=https VITE_REVERB_APP_KEY="${REVERB_APP_KEY}" VITE_REVERB_HOST="${REVERB_HOST}" VITE_REVERB_PORT="${REVERB_PORT}" VITE_REVERB_SCHEME="${REVERB_SCHEME}" broadcast config is `connections' => [ 'reverb' => [ 'driver' => 'reverb', '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') === 'https', ], 'client_options' => [ // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html ], ], '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' => env('PUSHER_HOST') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com', 'port' => env('PUSHER_PORT', 443), 'scheme' => env('PUSHER_SCHEME', 'https'), 'encrypted' => true, 'useTLS' => env('PUSHER_SCHEME', 'https') === 'https', ], 'client_options' => [ // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html ], ], ]` event broadcasting is `namespace App\Events; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; class TypingEvent implements ShouldBroadcastNow { use Dispatchable, InteractsWithSockets, SerializesModels; public $f; public $t; public $ty; /** * Create a new event instance. */ public function __construct($from,$to,$type) { $this->from = $f; $this->to = $t; $this->type = $ty; } /** * Get the channels the event should broadcast on. * * @return array */ public function broadcastOn(): array { return [ new PrivateChannel('typing'.$this->t), ]; } }` calling this function `public function deleteRR($id) { TypingEvent::dispatch(auth()->user()->id, $id,'stop'); }` route Broadcast::channel('typing{id}', function($user,$id){ return (int) $user->id === (int) $id; }); it returns error as above as i described here is nginx config file `server { listen 80; listen 443 ssl; client_max_body_size 256M; ssl_certificate /etc/ssl/abc.example.com.pem; ssl_certificate_key /etc/ssl/abc.example.com.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers 'String'; # Log files for Debugging access_log /var/log/nginx/abc.example.com.log; error_log /var/log/nginx/abc.example.com.log; # Webroot Directory for Laravel project root /abc.example.com/public; index index.php index.html index.htm; # Your Domain Name server_name abc.example.com; # Handle WebSocket connections location /app/ { proxy_pass http://0.0.0.0:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; proxy_set_header X-Forwarded-Proto $scheme; } # Handle regular HTTP requests location / { try_files $uri $uri/ /index.php?$query_string; } # PHP-FPM Configuration Nginx location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/run/php/php8.2-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } add_header Strict-Transport-Security "max-age=63072000; includeSubdomains;" always; add_header X-Frame-Options "deny" always; add_header X-XSS-Protection "1; mode=block" always; add_header X-Content-Type-Options "nosniff" always; }`
joedixon commented 1 week ago

Hey @amit772000, what does your web server configuration look like?

amit772000 commented 1 week ago

@joedixon i have just added my nginx web server configuration in the question. so you can take a look.

joedixon commented 1 week ago

Thanks @amit772000, it looks like your server is only listening for /app, but it will also need to listen for /apps

You can read more about that here: https://laravel.com/docs/11.x/reverb#web-server

amit772000 commented 1 week ago

@joedixon ok i read that document but i can not able to find the nginx example which provides any example to liste on /app and /apps both ? can you please suggest me how you are thinking ? so i can implement in my code and try it ? Thanks

ThohcIT commented 5 hours ago

@joedixon ok i read that document but i can not able to find the nginx example which provides any example to liste on /app and /apps both ? can you please suggest me how you are thinking ? so i can implement in my code and try it ? Thanks

worked with me:

ProxyPreserveHost On
<Location /app>
        ProxyPass ws://0.0.0.0:8080/app
        ProxyPassReverse ws://0.0.0.0:8080/app
</Location>
<Location /apps>
        ProxyPass http://0.0.0.0:8080/apps
        ProxyPassReverse http://0.0.0.0:8080/apps
</Location>