Info: I am doing this small tutorial here to show you guys how to use NodeBB and CloudFlare proxying while still using WebSockets since lots of people seem to look for it. I already posted a small explanation here, but people don't seem to find it / have problems - I added some extra explanation to this so that you can avoid the problems other people had.
NodeBB version: Should work with any, tested with v0.7.x
and v0.9.x
So. Basically what we're going to do is routing the WebSocket requests around CloudFlare while keeping the forum itself behind CloudFlare.
Disclaimer:
If you do this your root server is in general open to the public again. If you depend on CloudFlare's DDoS protection this will make it kind of useless. People who know what they are doing will be able to take your forum down quick if your root server has no own DDoS protection. DigitalOcean e.g. has none / I know of people who had their IP's nullrouted when being DDoS'ed at DigitalOcean.
Things you will have to replace in the following code snippets:
<domain.tld> -> your domain (e.g. `nodebb.org`)
<your.crt> -> the path to your ssl certificate (e.g. /home/ssl/org.nodebb.crt)
<your.key> -> the path to your ssl private key (e.g. /home/ssl/org.nodebb.key). This key was generated by yourself when you created your certificate sign request / .csr
<port> -> your NodeBB port
<0.0.0.0> -> your IPv4 address
<00:0000:0000:0000:0000:0000:0000:0000>` -> your IPv6 address in case you have one
CloudFlare:
Create these DNS records with grey clouds, which means you disable CF proxying:
A live.<domain.tld> <000.000.000.000>
AAAA live.<domain.tld> <0000:0000:0000:0000:0000:0000:0000:0000>
NodeBB:
We will configure NodeBB to route the WebSocket requests over the subdomain by adding this to our config.json
:
"socket.io": {
"transports": ["websocket", "polling"],
"address": "live.<domain.tld>"
}
Please make sure you add a comma to the element before "socket.io"
, otherwise it will be invalid JSON. Also paste the config in the JSON validator just to be sure the whole config is intact.
NGINX:
Get a free SSL certificate from Let's Encrypt or StartCom, and add this new server block to your NGINX configuration:
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate <your.crt>;
ssl_certificate_key <your.key>;
server_name live.<domain.tld>;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_http_version 1.1;
proxy_pass http://localhost:<port>;
}
}
Make sure that:
- your ssl certificate is valid and includes your subdomain
live.domain.tld
- you have at least 2 server blocks now in your NGINX configuration.
Then run service nginx configtest
to validate your new configuration. If it succeeds you can reload NGINX by using service nginx reload
And now you're done. Pretty simple. Hope this helps somebody using NodeBB.
In case something shouldn't be working please provide an error message, your NodeBB config without credentials / secrets and the NGINX server blocks .