skip to Main Content

I am trying (!) to use laravel reverb in my local setup ( dockerized php-fpm nginx mysql )
but not matter what port or host I am keep getting
WebSocket connection to 'ws://127.0.0.1:8070/app/02f265e93304b96ba8d8?protocol=7&client=js&version=8.3.0&flash=false' failed: which is bugging me since I am pretty sure about the env variables and tried EVERYTHING …
here are some of the assumptions you can have in my current situation :
1- Ran reverb:start inside the php-fpm container ( which I am not sure is the best way )
2- set env variables to correct values
3- Haven’t setup ssl certificates at all .
4- have echo.js pusher and broadcasting setup already .

Appreciate any thoughts.

2

Answers


  1. Check that the port (8070) is exposed in your Docker configuration (docker-compose.yml) and mapped to the host. You might need something like:
    services–>php-fpm–>ports–>8070:8070

    Use localhost instead of 127.0.0.1 for WebSocket connections since 127.0.0.1 inside the container refers to the container itself.

    Running reverb:start inside the PHP-FPM container might cause issues if it’s not properly mapped to external services or if the WebSocket server is trying to bind to 127.0.0.1. Consider running Reverb outside the container, or check the container logs to ensure there are no permission issues.

    NGINX Reverse Proxy Configuration

    location /app/ {
        proxy_pass http://127.0.0.1:8070;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    

    Although you’re not using SSL, it’s worth noting that modern browsers may block non-secure WebSocket connections, especially in production environments. Consider setting up SSL when you move to production to avoid such issues.

    PHP-FPM typically doesn’t serve WebSocket requests directly. Ensure that PHP-FPM is not interfering with the WebSocket server, and consider running the WebSocket server independently if possible.

    Login or Signup to reply.
  2. Make sure the WebSocket server is running on a port that Docker has opened up, like port 6001 for Laravel WebSockets.

    Then in your .env file set the BROADCAST_DRIVER and PUSHER

    configuration.BROADCAST_DRIVER=pusher
    PUSHER_APP_ID=your_app_id
    PUSHER_APP_KEY=your_app_key
    PUSHER_APP_SECRET=your_app_secret
    PUSHER_APP_CLUSTER=mt1
    MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
    MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
    

    and in your WebSocket

    LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT=null
    LARAVEL_WEBSOCKETS_SSL_LOCAL_PK=null
    LARAVEL_WEBSOCKETS_PORT=6001
    

    Else check in config/broadcasting.php the scheme is set to http since you are running in the local environment 'scheme' => 'http',

    Ensure that the WebSocket server and php-fpm can coexist in your Dockerfile, or add the WebSocket server as a separate service in your docker-compose.yml file:

    services:
      websockets:
        image: your-websocket-image
        ports:
          - "6001:6001"
        depends_on:
          - app
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search