Thanks so much for thinking of posting this...it just helped me out.
Laravel reverb | Nginx + Reverb
Myself have been struggling to get Reverb into production. Everything worked fine within sail (locally) but not into production.
One of the issues was that my connection was getting interrupted and the heartbeat of Reverb itself didn't happen.
Therefor I thought to explain to people how I did it and share my Nginx configuration.
server { listen 80; listen [::]:80; server_name URL_TO_SERVE; root NETWORK_PATH;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# Laravel Reverb
# The Websocket Client/Laravel Echo would connect and listen to this
location ~ /app/(?<reverbkey>.*) { # variable reverbkey
proxy_pass ht tp://127.0.0.1:8080/app/$reverbkey;
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_read_timeout 120;
proxy_send_timeout 120;
}
# The Laravel Backend would broadcast to this
location ~ ^/apps/(?<reverbid>[^/]+)/events$ { # variable reverbid
proxy_pass ht tp://127.0.0.1:8080/apps/$reverbid/events;
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;
proxy_read_timeout 120;
proxy_send_timeout 120;
}
# PHP-FPM configuration for Laravel
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; # Adjust PHP version if necessary
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
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$ {
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
I added proxy_read_timeout and proxy_send_timeout as I noticed the problem with the heartbeat was because nginx cuts the connection off. Nginx did that on the exact same time as the heartbeat should have been send.
I just want to give people the information so if someone search they have some information which I missed in my search.
Hope I help someone with this.
Please or to participate in this conversation.