Using CloudFlare with NodeBB

Pinned Tutorials
  • #1

    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.


    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. ``)
    <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
    <>    -> your IPv4 address
    <00:0000:0000:0000:0000:0000:0000:0000>` -> your IPv6 address in case you have one


    Create these DNS records with grey clouds, which means you disable CF proxying:

    • A live.<domain.tld> <>
    • AAAA live.<domain.tld> <0000:0000:0000:0000:0000:0000:0000:0000>


    We will configure NodeBB to route the WebSocket requests over the subdomain by adding this to our config.json:

    "": {
        "transports": ["websocket", "polling"],
        "address": "live.<domain.tld>"

    Please make sure you add a comma to the element before "", otherwise it will be invalid JSON. Also paste the config in the JSON validator just to be sure the whole config is intact.


    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 😄.

  • #2

    Awesome tutorial. I can remember this being asked pretty frequently (once every other week) when I first started working with NodeBB.

  • #3

    So my takeaway from this is that I can use CloudFlare's CDN functionality and route the websockets (which cannot be used on the CloudFlare free plan) around CF so that any image resources on my site can be served from CloudFlare. Correct?

  • #4

    @ThingBreaker Exactly 😄 Only the websockets directly connect to your server. The rest is connecting over CloudFlare.

  • #5

    @lenovouser, excellent! That was my first takeaway - but thought I'd get a plain restatement for anyone who reads this and might be newer to working with a CDN. 🙂

  • #6
    This post is deleted!
  • #7

    Can you share how you dealt with DDOS?

  • #8

    @nanjusoil you can always look into web traffic filtering, traffic shaping, and using a DDoS protected host.

  • #9

    @nanjusoil I think if you integrated Cloudfare then you can handle DDOS or go with their premium package.

  • #10

    Thank you 👍 . Currently I'm using Incapsula(they supported websocket in freetier) instead CloudFlare

  • #11

    @hieudang said:

    Thank you 👍 . Currently I'm using Incapsula(they supported websocket in freetier) instead CloudFlare

    @hieudang umm interesting, maybe you could write a little tutorial using incapsula, tellong a little more what are the advantages over using vloudflare in the free plan and the steps needed to configure their system with nodebb.

  • #12

    @hieudang but not TLS/SSL.

  • #13


    Just add to Incapsula as normal, but I don't run this case in production, only for testing.

    @AOKP You require too much on freetie =))

    But if you want, you can try crazy scenario

    YourNodeBBServer-->Incapsula-->CloudFlare Universal SSL

    Still work with my site 😄
    You can check here:

  • #14

    @hieudang Even though this seems to work, it definitely makes no sense to create what you did. Everything is going to CloudFlare anyway in your case. The only difference is that there is one more middleman where CloudFlare get's the data for your website from. There will be no speed improvement if you do this.

  • #15

    @lenovouser Offcourse, that's why I only use for testing and I say "crazy".🌷
    I emphasize "There ain't no such thing as a free lunch".
    Someone want cdn, antiddos, ssl more and more but FREE. 😗
    Hell no 💚

  • #16

    @hieudang I want none of these, except CloudFlare's caching and minify tools.

  • #17

    @hieudang I understand what you are trying to say, even though CloudFlare does provide all of these 3 things for free. But I don't want to turn this into a Incapsula vs. CloudFlare topic, I think we could create a new one for this in the Discussion category 😄

  • #18

    @lenovouser by the way. How would the configs have to look like, if your forum was installed in a folder, e.g. /forum?

  • #19

    @AOKP I can create a more easier to understand tutorial later, but here is how it looks for Minora at the moment. (Which is what I think you mean)

    Here are our current config files, just copied it out. I think the needed information is in there, don't worry about the includes. That's just part of our structure.


  • #20

    @AOKP As far as I know, Incapsula supported caching and minify tools ✌
    @all Sorry for off-topic, just for fun 👯
    OK, back to topic, how many method can I use CloudFlare with NodeBB?

      1. Follow lenovouser , but your IP will not be hidden.
      1. Upgrade to Enterprise CloudFlare Plan 😰 a lot of money
      1. Use middleman as I said, I'm not sure it will work fine. (IP blacklist...)
      1. Could you guys split one server to listen one will serve others request, so we can hide main IP
      1. ???? I'm thinking...

Suggested Topics

  • 1 Votes
    14 Posts

  • 2 Votes
    3 Posts

  • 0 Votes
    1 Posts

  • 0 Votes
    5 Posts

  • 2 Votes
    34 Posts

| | | |