NodeBB is a cutting-edge, open-source forum software crafted in JavaScript and Node.js, utilizing MongoDB as its default database system. It provides a plethora of features, including real-time notifications via web sockets, seamless social media integration, and an extensive REST API support.
In this guide, you will learn how to successfully install NodeBB on a Debian 12 server, utilizing MongoDB as the database and Nginx as a reverse proxy.
Prerequisites
Ensure you have these prerequisites before proceeding:
- An operational Debian 12 server.
- A non-root user possessing sudo privileges.
- A domain name successfully pointed to your server’s IP address.
Installing Dependencies
Begin by installing the necessary dependencies for NodeBB, which include Node.js, NPM (Node.js Package Manager), and Nginx from the Debian repository. Additionally, MongoDB will be installed via its official repository.
Initial step: Install the gnupg and curl packages on your Debian system using the command below.
sudo apt install gnupg curl -y
Add MongoDB’s GPG key and repository:
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | \ sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \ --dearmor
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/7.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
Update your Debian package index, then install MongoDB, Node.js, NPM, Nginx, and Git. Confirm the installation when prompted.
sudo apt update sudo apt install mongodb-org nodejs npm git nginx
Upon completion, reload the systemd manager:
sudo systemctl daemon-reload
Start, enable, and verify the MongoDB service status:
sudo systemctl enable --now mongod sudo systemctl status mongod
Confirmation of a running MongoDB service is seen below:
Verify Nginx service status. Nginx should be active and running.
sudo systemctl is-enabled nginx sudo systemctl status nginx
Lastly, check the Node.js and NPM versions:
sudo node-v sudo npm -v
Node.js 18 and NPM 9 should be installed successfully.
Setting up MongoDB Server
Proceed to enable MongoDB authentication, create an admin user, and establish a database and user for NodeBB.
Login to MongoDB:
mongosh
Create an admin user:
use admin db.createUser( { user: "admin", pwd: "MongoDBAdminPass", roles: [ { role: "root", db: "admin" } ] } )
Create a ‘nodebb’ database and user:
use nodebb db.createUser( { user: "nodebb", pwd: "NodeBBPassword", roles: [ { role: "readWrite", db: "nodebb" }, { role: "clusterMonitor", db: "admin" } ] } )
Exit MongoDB session:
quit()
Edit MongoDB configuration to enable authentication:
sudo nano /etc/mongod.conf
security: authorization: enabled
Save and close the file. Restart MongoDB to apply changes.
sudo systemctl restart mongod
Test MongoDB user login:
mongosh "mongodb://127.0.0.1:27017" --username nodebb --authenticationDatabase nodebb
Verify connection:
db.runCommand( { connectionStatus: 1, showPrivileges: false } ) quit()
Installing NodeBB
Complete MongoDB setup before proceeding to install NodeBB. Create a dedicated user, download node source, and set up a service file.
Create NodeBB user:
sudo adduser --system --no-create-home --home=/opt/nodebb --group nodebb
Clone NodeBB source and assign proper ownership:
git clone -b v3.x https://github.com/NodeBB/NodeBB.git /opt/nodebb sudo chown -R nodebb:nodebb /opt/nodebb
Configure NodeBB:
cd /opt/nodebb sudo su -s /bin/bash -c "./nodebb setup" nodebb
- Enter domain name for NodeBB.
- Accept default NodeBB secret by pressing ENTER.
- Disable anonymous plugin usage by selecting no.
- Select MongoDB as the database.
- Enter MongoDB URL: mongodb://nodebb:NodeBBPassword@127.0.0.1:27017/nodebb
- Provide administrator credentials and email for NodeBB.
Upon completion, “NodeBB Setup Completed” will be displayed along with a command to run NodeBB.
Manually start or stop NodeBB as needed using these commands:
sudo su -s /bin/bash -c "./nodebb start" nodebb sudo su -s /bin/bash -c "./nodebb stop" nodebb
To centralize NodeBB management, set up a systemd service file:
Create and insert the following into the file /etc/systemd/system/nodebb.service:
sudo nano /etc/systemd/system/nodebb.service
[Unit] Description=NodeBB Documentation=https://docs.nodebb.org After=system.slice multi-user.target mongod.service [Service] Type=simple User=nodebb StandardError=syslog SyslogIdentifier=nodebb Environment=NODE_ENV=production WorkingDirectory=/opt/nodebb ExecStart=/usr/bin/env node loader.js --no-silent --no-daemon Restart=always [Install] WantedBy=multi-user.target
Save, close, and reload systemd:
sudo systemctl daemon-reload
Enable and start NodeBB service:
sudo systemctl start nodebb sudo systemctl enable nodebb
Check the NodeBB service status:
sudo systemctl status nodebb
Confirm that NodeBB is operating as a systemd service:
Setting up Nginx as a Reverse Proxy
NodeBB runs on port ‘4567’. You can use Nginx to redirect requests to NodeBB by setting up a new server block.
Create a server block file:
sudo nano /etc/nginx/sites-available/nodebb
Add the following to enable Nginx as a reverse proxy, replacing ‘server_name’ with your actual domain:
server { listen 80; server_name forum.howtoforge.local; location / { 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_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"; } }
Activate and test Nginx configuration:
sudo ln -s /etc/nginx/sites-available/nodebb /etc/nginx/sites-enabled/ sudo nginx -t
Restart Nginx service:
sudo systemctl restart nginx
Securing NodeBB with HTTPS
Utilize Certbot and Letsencrypt to secure NodeBB with HTTPS. For local testing or if this step is unnecessary, generate self-signed certificates instead.
Install Certbot and its Nginx plugin:
sudo apt install certbot python3-certbot-nginx
Generate SSL certificates for NodeBB (replace the email and domain details):
sudo certbot --nginx --agree-tos --no-eff-email --redirect --hsts --staple-ocsp --email admin@howtoforge.local -d forum.hwdomain.i
After completing this step, NodeBB should be secured with HTTPS, and certificates are located in the /etc/letsencrypt/live/domain.com directory.
Accessing NodeBB
Open your browser and visit https://forum.howtoforge.local/ to see NodeBB’s default index page.
From the homepage, navigate to the Login menu to access the NodeBB login page:
Upon successful login, you will reach the user dashboard.
Access the NodeBB administration dashboard via the Admin menu.
Conclusion
Congratulations! You have successfully installed NodeBB on your Debian 12 server, integrated with a MongoDB database and safeguarded against threats using an Nginx reverse proxy.
FAQs
Q1: What is NodeBB?
A: NodeBB is an open-source forum platform using Node.js, allowing real-time interactions and scalability.
Q2: Why use Nginx as a reverse proxy for NodeBB?
A: Nginx helps manage traffic efficiently, provides security enhancements, and facilitates things like SSL termination before reaching the NodeBB instance on `port 4567`.
Q3: How to update NodeBB?
A: To update NodeBB, navigate to your NodeBB directory and execute `git pull && ./nodebb upgrade` followed by a restart of NodeBB service.
Q4: How can I troubleshoot issues with NodeBB?
A: Check logs in `/opt/nodebb/logs/`, run NodeBB in development mode for more verbose output, or consult the community for solutions.