Search code examples
laraveldockerwebsocketdevilbox

Devilbox (docker) + Laravel Websockets


Trying to get the two to work together. Is there something I'm missing or way to debug why it's not working?

Edited .devilbox/nginx.yml as suggested here although trying to contain it to path: wsapp

---
###
### Basic vHost skeleton
###
vhost: |
  server {
      listen       __PORT____DEFAULT_VHOST__;
      server_name  __VHOST_NAME__ *.__VHOST_NAME__;

      access_log   "__ACCESS_LOG__" combined;
      error_log    "__ERROR_LOG__" warn;

      # Reverse Proxy definition (Ensure to adjust the port, currently '8000')
      location /wsapp/ {
        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_pass http://php:6001;
      }

  __REDIRECT__
  __SSL__
  __VHOST_DOCROOT__
  __VHOST_RPROXY__
  __PHP_FPM__
  __ALIASES__
  __DENIES__
  __SERVER_STATUS__
      # Custom directives
  __CUSTOM__
  }

Installed laravel-websockets and configured to use '/wsapp'

Visit the dashboard to test: https://example.local/laravel-websockets

But console has error:

Firefox can’t establish a connection to the server at wss://example.local:6001/wsapp/app/a558686cac00228eb003?protocol=7&client=js&version=4.3.1&flash=false. 2 pusher.min.js:8:6335 The connection to wss://example.local:6001/wsapp/app/a558686cac00228eb003?protocol=7&client=js&version=4.3.1&flash=false was interrupted while the page was loading. pusher.min.js:8:6335


Solution

  • I've Created a Setup that works...

    first you need 2 domains in devilbox...

    1. For you Laravel App (example.local)
    2. For you Laravel Websocket (socket.example.local)

    on your socket.example.local directory...

    create htdocs and .devilbox here you'll add your nginx.yml file

    when you try to connect to your socket.

    • don't use the port anymore...
    • and don't isolate the socket to /wsapp anymore...
    • use socket.example.local in .env PUSHER_HOST value

    run your laravel websocket on example.local...

    visit /laravel-websockets dashboard... remove the port value then click connect

    I don't suggest you'll serve your socket in /wsapp because it's hard to configure nginx to serve 2 apps... (it's hard for me, maybe someone more expert on nginx can suggest something regarding this setup)

    but that's my solution... if you didn't understand, please do comment