Laravel Reverb on Cloudflare on Forge
A setup from hell, it seems nobody has bothered to test this, the good thing is I've tested it so you don't have too.
This website gets its real time events (Chat Messages) through Laravel Reverb hosted on Laravel Forge with an SSL Certificate on Cloudflare.
It is seemingly evident that I might be the only person using such a setup. All the help guides and issues trackers always reference Lets Encrypt which allows to see the hostnames when generating the certificate. You can't change them, but it gives you validation that you're configuring.... something correctly. You get no joy with Cloudflare and need to dig into the NGINX Config to actually configure and set things up correctly. I assume because the SSL certificate only registers on the main domain, and since any alias or wildcards are part of the same nginx config (Not an offshot like Reverb is). And yes I tried the method of turning off alias, putting it back on, only having the wildcard active while upside down on a Tuesday. None of it worked.
Anyway, assuming aside, here is what worked for me.
- Create Origin Server certs on Cloudflare
- Add them to forge then activate on the domain
- Activate Laravel Reverb on the main application page, leave the settings default
- SSH into your Forge box, cat the nginx config which is running your domain cat /etc/nginx/sites-enabled/brawhammer.com
- Find the lines which reference the ssl_certificate and key
Mines looked like this
# FORGE SSL (DO NOT REMOVE!) ssl_certificate /etc/nginx/ssl/brawhammer.com/xxxx/server.crt; ssl_certificate_key /etc/nginx/ssl/brawhammer.com/xxxx/server.key;
Copy this to your reverb config
This is what your reverb config will look like BEFORE you make this change
server { listen 80; listen [::]:80; server_name ws.brawhammer.com; server_tokens off; # FORGE SSL (DO NOT REMOVE!) # ssl_certificate; # ssl_certificate_key;
This is what it should look like after
server { listen 443; listen [::]:443; server_name ws.brawhammer.com; server_tokens off; # FORGE SSL (DO NOT REMOVE!) # ssl_certificate; # ssl_certificate_key; ssl_certificate /etc/nginx/ssl/brawhammer.com/2679012/server.crt; ssl_certificate_key /etc/nginx/ssl/brawhammer.com/2679012/server.key;
All we're doing is changing the port it's listening on, and adding the keys which are wildcarded so should work anyway.
And that's it! You should now have Laravel Reverb running on Forge with a Cloudflare SSL cert.
Interested in seeing this in action? The streaming page has live chat, feel free to talk in there!