1

Triying to setup ssl for laravel reverb using nginx on ubuntu

Laravel reverb docs

/etc/supervisor/conf.d/websockets.conf

[program:websockets-l11]
command=/usr/bin/php /var/www/l11/artisan reverb:start
numprocs=1
autostart=true
autorestart=true
user=ubuntu

Nginx

server {
    root /var/www/l11/public;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";
    index index.php;
    server_name l11.example.com;
    charset utf-8;
location / {
    try_files $uri $uri/ /index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }
error_page 404 /index.php;

location ~ \.php$ {
    include snippets/fastcgi-php.conf;

    fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    include fastcgi_params;
}

location /websocket {
    proxy_http_version 1.1;
    proxy_set_header Host $http_host;
    proxy_set_header Scheme $scheme;
    proxy_set_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";

    proxy_pass http://0.0.0.0:8080;
}

listen 80; # managed by Certbot
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

echo-bLibrbhu.js:8 WebSocket connection to 'wss://l11.example.com:8080/app/lkak9yjwbphvj8kwlzav?protocol=7&client=js&version=8.4.0-rc2&flash=false' failed

1 Answers1

1

It took me a while but I managed to get it working, here are some very important things that can prevent Reverb from working on a production server:

  1. The port 8080 (or any other port you want to use) must be open an accessible, you can do this by configuring your firewall when creating the server at your hosting provider. To verify if it is indeed open, you must start the reverb server with php artisan reverb:start --debug, then head over to https://www.yougetsignal.com/tools/open-ports/ and enter the server IP address and port you want to check.

  2. You must ensure that the .env variables related to Reverb are correctly set, specially BROADCAST_CONNECTION which must be always set to reverb, it is default set to log. And also, ensure that REVERB_HOST is set to your domain name or server IP.

  3. After you make any changes to the .env file, you must rebuild your node packages with npm run build.

Vinny
  • 111