How to

How to Install Nodebb with MongoDB and Nginx on Ubuntu

How to install NodeBB

Estimated reading time: 2 minutes

NodeBB is free and open-source bulletin board software. The application is written in Nodejs and is fast becoming a popular solution. The software has several advantages over the free and open-source competition, such as:

  • JavaScript on the node (Nodejs) is extremely fast
  • The application takes advantage of Single Page Application (SPA) principals
  • Takes advantage of NoSQL database software
  • Includes modern web app features straight out of the box

In this tutorial we will be installing NodeBB on the following a DigitalOcean server running Ubuntu. We will then install Nginx as the web server, MongoDB as the database software, Nodejs and finally, NodeBB.

Should I use DigitalOcean?

You don’t have to use DigitalOcean, but if you’re asking yourself if you should, the answer is yes. DigitalOcean has a fantastic service at a Fantastic price. We will be using the one-click MongoDB server, allowing us to skip the MongoDB installation process completely. There are several other major advantages to using DigitalOcean, but this is not the post for that.

To get $10 free from DigitalOcean, register with signup HERE.

Start your DigitalOcean server

After registering an account with DigitalOcean, click the big green button at the top of the page that says ‘Create Droplet’. You will want to click the One-Click Apps tab and select ‘MongoDB’.

Select your plan, the $5 per month server is more than enough to run your forum during development. Choose your location, name your server and click ‘Create’.

How to create a digitalocean droplet for NodeBB

When your server has finished being generated, you will receive an email with your server IP address, root user (usually root) and your password. You can then connect to the server with PuTTy.

Create a MongoDB database and user

Like all good applications, MongoDB has a built-in console tool that allows us to quickly communicate with the application. To access the MongoDB console type:

$ mongo

Creating a MongoDB database is extremely easy, to create one called ‘nodebb’ issue the following command.

$ use nodebb

To create a user called ‘nodebb’ that has access to our nodebb database, issue the following command:

$ db.createUser(
   {
     user: "nodebb",
     pwd: "your-strong-password",
     roles: [ "readWrite", "dbAdmin" ]
   }
)

Install Nodejs

The following command will install v4.2 Argon.

$ sudo curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -

Then install Nodejs and some dependencies

$ sudo apt-get install -y git nodejs mongodb build-essential

Navigate to where you want NodeBB to live. Personally, i use /var/www, but you can use whatever you like.

$ cd /var
$ mkdir www
$ cd www
$ git clone -b v1.x.x https://github.com/NodeBB/NodeBB.git nodebb

Next, we will install NodeBB and obtain its dependencies

$ cd nodebb
$ npm install --production

Next, we will run the NodeBB setup. This is where you will enter your MongoDB username, password and database. You will then be asked for an administrator user, email and password.

$ ./nodebb setup

Finally, we can start NodeBB by running:

$ ./nodebb start

You should then be able to access your NodeBB installation by visiting http://ip-address:4567

However, this is not desirable and we will almost always want to use a domain name. So lets now configure Nginx to handle requests from the internet.

Install Nginx

$ sudo apt-get update
$ sudo apt-get install nginx

That’s it, Nginx is now installed and you can do the usual start, stop and restart with the following command:

$ service nginx start
$ service nginx stop
$ service nginx stop

Configure Nginx 

Nginx is going to act like a reverse proxy for your domain. When a user types in your-domain, they are going to serves the pages from your-ip:4567. To do this, you will need to navigate to your configuration file.

$ cd /etc/nginx/sites-available/

Personally, I remove the configuration and create a new one.

$ rm default
$ nano default

Inside the configuration file I use the following:

server {
    listen 80;

    server_name domain.com;

    location / {
    root /var/www/nodebb;
        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_pass http://127.0.0.1:4567/;
        proxy_redirect off;

        # Socket.IO Support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

You will need to change domain.com to your own domain name and the root path to wherever you installed NodeBB.

Top