Search code examples
laravellaravel-reverb

Laravel-reverb : cURL error 56: Received HTTP code 503 from proxy after CONNECT


I'm trying to use laravel reverb ( localhost ) but jobs fails with this error :

GuzzleHttp\Exception\RequestException: cURL error 56: Received HTTP code 503 from proxy after CONNECT (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://sockets.my-app/apps/154811/events?auth_key=ht3fidxq3ibryisgbwvs&auth_timestamp=1713439684&auth_version=1.0&body_md5=4d4063e1f80149f3f49cd0ca8f7b0e9b&auth_signature=09cc000f73028b8a2f0467bbdac413153847ad336247071a111c64f63aa2f289 in /var/www/may-app/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:211

my .env

...
REVERB_HOST="sockets.my-app"
REVERB_PORT=443
REVERB_SCHEME=https
REVERB_SERVER_HOST=0.0.0.0
REVERB_SERVER_PORT=8080
...

here is my NGINX conf:

server {
   listen 443;
   listen [::]:443;
   server_name sockets.my-app;

    ssl on;
    ssl_certificate /etc/ssl/certs/***.fr.cer;
    ssl_certificate_key /etc/ssl/private/***.fr.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1.2;
    ssl_ciphers HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA;
    ssl_prefer_server_ciphers on;

    location / {
        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass http://0.0.0.0:8080;
    }
}

i dispatch my event in my controller like this:

CommentCreated::dispatch($comment);

so i can see that the job failed:

2024-04-18 12:24:37 ***\***\app\Events\CommentCreated ................ RUNNING
2024-04-18 12:24:37 ***\***\app\Events\CommentCreated ............. 14.97ms FAIL

Does anyone have an idea of ​​what part I'm missing? thanks in advance


Solution

  • I finally found the solution. I'm putting it here, if that helps.

    the idea is to run a web server and reverb on the same machine. I use an nginx reverse proxy to act as an intermediary between the user and reverb.

    .env

    REVERB_HOST="sockets.my-domain.com"
    REVERB_PORT=443
    REVERB_SCHEME=https
    REVERB_SERVER_HOST=127.0.0.1
    REVERB_SERVER_PORT=8080
    REVERB_SERVER_SCHEME=http
    
    VITE_REVERB_SERVER_HOST='${REVERB_SERVER_HOST}'
    VITE_REVERB_SERVER_PORT='${REVERB_SERVER_PORT}'
    VITE_REVERB_SERVER_SCHEME='${REVERB_SERVER_SCHEME}'
    VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
    VITE_REVERB_HOST="${REVERB_HOST}"
    VITE_REVERB_PORT="${REVERB_PORT}"
    VITE_REVERB_SCHEME="${REVERB_SCHEME}"
    

    resources/js/echo.js

    import Echo from 'laravel-echo';
    
    import Pusher from 'pusher-js';
    window.Pusher = Pusher;
    
    window.Echo = new Echo({
       broadcaster: 'reverb',
       key: import.meta.env.VITE_REVERB_APP_KEY,
        wsHost: import.meta.env.VITE_REVERB_HOST,
        wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
        wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
        forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
        enabledTransports: ['ws', 'wss'],
    });
    

    config/broadcasting

        'reverb' => [
            'driver' => 'reverb',
            'key' => env('REVERB_APP_KEY'),
            'secret' => env('REVERB_APP_SECRET'),
            'app_id' => env('REVERB_APP_ID'),
            'options' => [
                'host' => env('REVERB_SERVER_HOST'),
                'port' => env('REVERB_SERVER_PORT', 443),
                'scheme' => env('REVERB_SERVER_SCHEME', 'https'),
                'useTLS' => env('REVERB_SERVER_SCHEME', 'https') === 'https',
            ],
            'client_options' => [
                'verify' => false,
            ],
    

    config/reverb

     'apps' => [
            [
                'key' => env('REVERB_APP_KEY'),
                'secret' => env('REVERB_APP_SECRET'),
                'app_id' => env('REVERB_APP_ID'),
                'options' => [
                    'host' => env('REVERB_SERVER_HOST'),
                    'port' => env('REVERB_SERVER_PORT', 443),
                    'scheme' => env('REVERB_SERVER_SCHEME', 'https'),
                    'useTLS' => env('REVERB_SERVER_SCHEME', 'https') === 'https',
                ],
                'allowed_origins' => ['*'],
                'ping_interval' => env('REVERB_APP_PING_INTERVAL', 60),
                'max_message_size' => env('REVERB_APP_MAX_MESSAGE_SIZE', 10_000),
            ],
    

    conf NGINX

    server {
       listen 443;
       listen [::]:443;
      server_name sockets.my-domain.com;
    
    ssl on;
    ssl_certificate /etc/ssl/certs/****.fr.cer;
    ssl_certificate_key /etc/ssl/private/****.fr.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1.2;
    ssl_ciphers HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA;
    ssl_prefer_server_ciphers on;
    
    location / {
        proxy_http_version 1.1;
        #proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass http://0.0.0.0:8080;
        }
    }
    

    it works very well