Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rmlaptopabs's avatar

Reverb WebSockets Integration

I am creating a custom integration with Laravel where I am sending real time sensor data to display that data on a web page. I am using websockets because of the real-time communications, and being a client, I don't need a public IP address for each client either. I am using the wss scheme and using nginx for the SSL handshake along with the reverse proxy (http scheme) to connect to Reverb. The setup / configuration seems straight forward, and it all makes sense. The problem that I am having is that I cannot connect to the Reverb server - not through nginx, or locally (curl or wscat). I can see when I connect with https curl, the SSL handshake is successful, but I get a 404 Not Found error. I get the same 404 error connecting directly to Reverb locally at http://127.0.0.1:8080. I don't understand the endpoint - in the nginx config, I configured a new server with a location pointing to a websockets/read route in my api.php file. I don't know if that is correct - I am unclear if the route is for an http request, or if the route works with web sockets too. I was looking through the logs, and I found an endpoint that make zero sense to me - app/u9trj9xcpdebdbqfmkik. I used Postman web sockets to connect to this end point and I was able to successfully connect to the Reverb server and send messages. The odd thing - I was missing an "event" field in the message I was sending, so I was getting a Pusher error response. I am seeing these messages from Postman in the reverb-access log - why do I have a Pusher error? I don't know where this endpoint originated from - it is something that is randomly generated. (I also need to mention - there is nothing else connecting to Reverb - I am testing with Postman and my single client). I have done all the basic troubleshooting - Reverb is running 0.0.0.0:8080, port 8080 is open through the firewall, configurations have been checked several times. I feel like I'm rambling on, so to keep things less confusing, I'll stop here. Thanks in advance for any help.

0 likes
5 replies
LaryAI's avatar
Level 58

To address the issue you're facing with integrating WebSockets in your Laravel application using Reverb, let's break down the problem and provide a solution step-by-step.

Understanding the Setup

  1. WebSocket Endpoint: Ensure that your WebSocket server (Reverb) is correctly set up to listen on the appropriate port and IP address. You mentioned it's running on 0.0.0.0:8080, which should be accessible from your local machine.

  2. Nginx Configuration: Your Nginx configuration should correctly proxy WebSocket connections. Here's a basic example of how your Nginx configuration might look:

    server {
        listen 443 ssl;
        server_name yourdomain.com;
    
        ssl_certificate /path/to/ssl_certificate.crt;
        ssl_certificate_key /path/to/ssl_certificate.key;
    
        location /websockets {
            proxy_pass http://127.0.0.1:8080;
            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;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
    
  3. Laravel Route: Ensure that your Laravel application has a route defined for handling WebSocket connections. Typically, WebSocket connections are not handled by Laravel routes directly but by a WebSocket server. However, if you are using a package like Laravel WebSockets, you might have a route like this:

    Route::webSockets('/websockets', function () {
        // WebSocket handling logic
    });
    

Troubleshooting Steps

  1. Check WebSocket Server: Verify that your WebSocket server is running and accessible. You can use tools like wscat to test the connection locally:

    wscat -c ws://127.0.0.1:8080/websockets
    
  2. Nginx Logs: Check the Nginx error and access logs for any clues about the 404 error. This might indicate that the request is not being routed correctly.

  3. Firewall and Network: Ensure that your firewall settings allow traffic on port 8080 and that there are no network issues preventing access to the WebSocket server.

  4. Pusher Error: The Pusher error you mentioned might be related to the format of the messages you're sending. Ensure that your messages include all required fields, such as the "event" field.

  5. Endpoint Confusion: The endpoint you found (app/u9trj9xcpdebdbqfmkik) might be a dynamically generated endpoint by a service like Pusher or a similar WebSocket service. Ensure that your client is connecting to the correct endpoint as expected by your WebSocket server.

Conclusion

If you continue to face issues, consider simplifying your setup by testing each component independently. Start with a basic WebSocket server and client setup to ensure connectivity, then gradually integrate it with your Laravel application and Nginx configuration. This approach can help isolate the problem and make troubleshooting more manageable.

ianflanagan1's avatar

I'm not an expert but I got it working (but I only need the server->clients direction)

REVERB_APP_ID=<random>
REVERB_APP_KEY=<random>
REVERB_APP_SECRET=<random>
REVERB_HOST=example.com
REVERB_PORT=443
REVERB_SCHEME=https
REVERB_SERVER_HOST=0.0.0.0
REVERB_SERVER_PORT=8079

Then php artisan reverb:start will work for testing, but long term need Supervisor to keep the Reverb process running after you close the terminal.

If found that closing the firewall for 8080 (or in my case 8079) didn't affect it, so I guess it's using 8079 internally and using 443 for external connections. I don't have time to learn about it now, just hacking things together. Hope this helps you

JussiMannisto's avatar

@ianflanagan1

If found that closing the firewall for 8080 (or in my case 8079) didn't affect it, so I guess it's actually using port 443?

In your setup, websocket traffic is proxied through Nginx (443) to the local Reverb socket (8079). That's good because it lets Nginx deal with client-server traffic encryption and you don't have to set up TLS for Reverb separately.

(but only using in the server->clients direction)

You need to set up a reverse proxy for two endpoints: /app and /apps, as mentioned in the docs. You already have the /app location. You can just duplicate that, changing the path to /apps.

1 like
JussiMannisto's avatar

@rmlaptopabs Your post is very hard to read because it's all one big block of text. You should break it into paragraphs to make it more readable. You might get more replies that way.

Please or to participate in this conversation.