After setting up reverb to be running on your vps, there are few changes you need to make all your server route websocket request to your laravel reverb.
🔧 NGINX Configuration
To proxy WebSocket requests to Laravel Reverb via Nginx, you must edit your virtual host (vhost
) file or Nginx site configuration.
Add the following location
block inside your server block:
Copy location /app {
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Scheme $scheme;
proxy_s_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";
# CORS headers for WebSocket
add_header Access-Control-Allow-Origin *; # Or specify your domain
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'Origin, Content-Type, Accept, X-Requested-With';
proxy_pass http://127.0.0.1:6001;
}
⚠️ Important
Make sure the IP address and port in proxy_pass
match the Reverb server host and port defined in your .env
file:
Copy REVERB_SERVER_HOST=127.0.0.1
REVERB_SERVER_PORT=6001
If you change these values in .env
, you must also update the Nginx configuration to reflect the new host and port.
After editing the config:
Copy sudo nginx -t # Test the config
sudo systemctl reload nginx
🔧 Apache Configuration
If you are using Apache , ensure the following is added to your virtual host configuration:
Copy <VirtualHost *:80>
ServerName yourdomain.com
# Usual Laravel setup...
DocumentRoot /var/www/yourproject/public
<Directory /var/www/yourproject/public>
Options Indexes FollowSyLinks
AllowOverride All
Require all granted
</Directory>
# WebSocket proxy configuration
ProxyPass "/app" "http://127.0.0.1:6001/app"
ProxyPassReverse "/app" "http://127.0.0.1:6001/app"
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /app/(.*) ws://127.0.0.1:6001/app/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /app/(.*) http://127.0.0.1:6001/app/$1 [P,L]
# Optional CORS headers
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "GET, POST, OPTIONS"
Header always set Access-Control-Allow-Headers "Origin, Content-Type, Accept, X-Requested-With"
</VirtualHost>
⚠️ Important
As with Nginx, you must ensure that the IP and port (127.0.0.1:6001
) align with:
Copy REVERB_SERVER_HOST=127.0.0.1
REVERB_SERVER_PORT=6001
Apply changes and restart Apache:
Copy sudo a2enmod proxy proxy_http proxy_wstunnel headers rewrite
sudo systemctl restart apache2