skip to Main Content

I am working on a website which is an online game using Laravel 11 with View 3 and Reverb (SPA without SSR for now). On the localhost the websockets work, but when I uploaded it to the production server with Apache they don’t work.

On localhost in .env I have
REVERB_HOST="localhost"
REVERB_PORT=8080
REVERB_SCHEME=http

In production I change them to

REVERB_HOST="www.mydomain.com"
REVERB_PORT=443
REVERB_SCHEME=https

Also in the virtual host file I add

<VirtualHost 192.168.100.12:443>
...
 SSLEngine On
 ProxyPass "/app" "ws://0.0.0.0:8080/app"
 ProxyPassReverse "/app" "ws://0.0.0.0:8080/app"
</VirtualHost>

After these settings in the browser tab for Network / websockets I now get that there is a connection established

{"event":"pusher:connection_established","data":"{"socket_id":"325487270.879942365","activity_timeout":30}"}
{"event":"pusher:subscribe","data":{"auth":"yzvrte6lfsudidxcfwkg:4055a502db436191e71198aeadf394db1defd0850c86e55f37fde6d59a9e83eb","channel":"private-user.3"}}
{"event":"pusher_internal:subscription_succeeded","data":"{}","channel":"private-user.3"}

As well as pinging periodically. But when the server tries to send data through the websocket I get the error

The POST method is not supported for route apps/174502/events. Supported methods: GET, HEAD.

This route is located in /vendor/laravel/reverb/src/Servers/Reverb/Factory.php


    protected static function pusherRoutes(): RouteCollection
    {
        $routes = new RouteCollection;
...
        $routes->add('events', Route::post('/apps/{appId}/events', new EventsController));
        return $routes;
    }

Why is it giving me this error? I might be doing something wrong in the configuration. Does anyone have any idea how to properly configure Reverb for Apache?

2

Answers


  1. After struggling with this for almost 2 days, I have finally managed to get Reverb working on AWS LAMP server in production.
    You need to add a few more things to your .env file

    
    BROADCAST_CONNECTION=reverb 
    QUEUE_CONNECTION=sync
    REVERB_SERVER=reverb
    REVERB_SERVER_HOST=0.0.0.0
    REVERB_SERVER_PORT=8080
    REVERB_APP_ID= replace_with_your_keys
    REVERB_APP_KEY=replace_with_your_keys
    REVERB_APP_SECRET=replace_with_your_keys
    REVERB_HOST=yourdomain.com
    REVERB_PORT=443
    REVERB_SCHEME=https
    
    # if you use vite add this too, same info
    VITE_REVERB_APP_KEY=replace_with_your_keys
    VITE_REVERB_HOST=yourdomain.com
    VITE_REVERB_PORT=443
    VITE_REVERB_SCHEME=https
    

    That is all, you don’t need to setup reverse proxy or open any port.

    Login or Signup to reply.
  2. For me the correct/required Apache config was/is:

    # Laravel Reverb
    ProxyPass /app ws://0.0.0.0:8080/app
    ProxyPassReverse /app ws://0.0.0.0:8080/app
    ProxyPass /apps http://0.0.0.0:8080/apps
    ProxyPassReverse /apps http://0.0.0.0:8080/apps
    

    Note that as per documentation Reverb uses two different endpoints, /app handles websocket connections and /apps handles api requests.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search