Install NodeBB Forum on Compute Engine | Google Cloud(GCP)
Updated: Jan 28
Prerequisites:
You will need the following items to complete this tutorial.
A Compute Engine VM instance up and running with Ubuntu Pro 20.04 LTS.
A Cloud SQL Instance up and running with PostgreSQL.
A Domain (Registered at any hosting provider).
Hostname Configuration.
Lets Encrypt SSL (Wildcard) with Nginx Configuration.
What is NodeBB?.
Node.js is used to power NodeBB, which is forum software. For real-time interactions and alerts, it uses web sockets. NodeBB is an open-source project that is fully free and easy to use. It provides plenty of opportunities to establish and grow your wide community by mobile responsive and giving integrated multi-localization support. NodeBB supports topic tagging, making it easier for users to find relevant web stuff. The platform interfaces with various third-party services, such as Ghost, WordPress, and others, allowing users to establish forums where they may share ideas and improve communication.
Step - 1. Create VPC Firewall Rules for NobeBB.
Add Ingress firewall rules.
Go to the Firewall rules page in the VPC network section in the Cloud Console.
Click Create a firewall rule.
On the Create a firewall rule page, enter a name and description.
In the Targets menu, select Specified target tags.
In the Target tags field, Type node-firewall.
In the Source IP ranges field, enter 0.0.0.0/0.
In the Protocols and ports section, select Specified protocols and ports.
Select TCP and enter the port: 80, 443, 4567
Click Create.
Add Egress firewall rules
Go to the Firewall rules page in the VPC network section in the Cloud Console.
Click Create a firewall rule.
On the Create a firewall rule page, enter a name and description.
In the Direction of Traffic, choose Egress.
In the Targets menu, select Specified target tags.
In the Target tags field, Type node-firewall.
In the Destination IP ranges field, enter 0.0.0.0/0.
In the Protocols and ports section, select Allow all.
Click Create.

Step - 2: Deploy a Compute Engine VM Instance.
Log into Google Cloud Console.
In the Cloud Console, Navigate to Compute Engine VM Instance.
In the VM instance interface, click on the "Create Instance" option and specify the "Name" of the instance, Region, and Zone.
In the Machine Configuration section, Select the Series and Machine type.
In the Boot Disk Section, click on the "change" option and select the "operating system" to "Ubuntu Pro" and "Version" to "Ubuntu 20.04 LTS Pro server.". Optional: Change the "Boot disk type." and "Size" based on your preference or leave them for default settings.
In the networking interface, type NodeBB firewall network tag. (For instance, "node-firewall.". Refer to step - 1 above).
Type your FQDN(Fully-Qualified Domain Name) in the hostname field.

Expand the "default" and "External IP" fields in the network interface section, click on the "Create IP Address" option, and reserve a static IP address to the instance.

Finally, click on the "create" option to deploy a VM instance.
Step - 3: Create a Cloud SQL instance.
Navigate to the "Cloud SQL." interface in the Google Cloud Console.
In the Cloud SQL interface, create a new instance with "PostgreSQL" and specify the authorized networks to access the instance.

In the Cloud SQL instance interface, navigate to the database section and create a new database for NodeBB. For example ''node-cloud-sql".
Step - 4: Installing NodeBB on Compute Engine.
In the Compute Engine VM instance interface, click on the "SSH" option on the NodeBB instance.
Installing Node.js
curl -sL https://deb.nodesource.com/setup_17.x | sudo -E bash -
sudo apt-get install -y nodejs
Check that Node.js and npm are installed correctly.
node -v
npm -v
Output
info@nodebb:~$ node -v
v17.3.1
info@nodebb:~$ npm -v
8.3.0
Installing NodeBB
First, we'll need to install git, which is used to distribute NodeBB.
sudo apt-get install -y git
After that, clone NodeBB to a suitable location.
git clone -b v1.19.x https://github.com/NodeBB/NodeBB.git nodebb
Open NodeBB directory.
cd nodebb
To install NodeBB via the Web interface.
./nodebb install
Output
2022-01-14T19:38:50.554Z [4985] - info: Launching web installer on port 4567
2022-01-14T19:38:50.584Z [4985] - info: [installer] Found setup.json, populating default values
2022-01-14T19:38:52.772Z [4985] - info: Web installer listening on
Initial Setup
In the browser, type your VM instance External-IP along with 4567 port. For example, http://34.133.146.7:4567
In the NodeBB Web Installer interface, specify the administrator credentials.
In the database section, select the database type to "PostgreSQL."
Type the Cloud SQL Instance IP address in the "Host IP" field.

Lastly, type PostgreSQL username, password, and database name.
Finally, click on the "Install NodeBB" option to deploy. Once the installation is done, click on the "Launch NodeBB" option and switch back to the terminal (SSH window) to verify the installation process.
Output
NodeBB Setup Completed. Run "./nodebb start" to manually start your NodeBB server.
Starting NodeBB
"./nodebb stop" to stop the NodeBB server
"./nodebb log" to view server output
"./nodebb restart" to restart NodeBB
Next, log into NodeBB using administrator credentials.

Step - 5: Hostname (FQDN) Configuration
To configure hostname, you may require a domain. (Register a domain or else use an existing domain.)
Login to your domain hosting provider, and add an "A Record" in the domain DNS that points to VM instance External IP.

Step - 6: Installing Nginx.
To serve NodeBB without a port, configure Nginx to forward all requests to a certain hostname (or subdomain) to an upstream NodeBB server operating on any port.
sudo apt-get install -y nginx
Verify the installation
nginx -v
Configuring Nginx
Open the sites-available directory
cd /etc/nginx/sites-available
Edit the "default" file.
sudo nano default
Comment the existing code and append the below code in the file.
Syntax
server {
listen 80;
server_name forum.example.com;
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";
}
}
Lastly, update the "server_name" row.
Output
server {
listen 80;
server_name nodebb.incapio.org.in;
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";
}
}
Finally, Save the file and reload the Nginx
sudo systemctl reload nginx
In the browser, type your domain name and verify the result.

Step - 7: Secure Nginx with Let's Encrypt
Install Certbot and it’s Nginx plugin.
sudo apt install certbot python3-certbot-nginx
Obtaining an SSL Certificate
Syntax
sudo certbot --nginx -d subdomain.yourdomain.com
Example
sudo certbot --nginx -d nodebb.incapio.org.in
If that works, certbot will ask you how you want to set up your HTTPS settings.
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/default
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://nodebb.incapio.org.in

Conclusion:
Here are some recommended tips and tricks.
To install NodeBB for production, make sure to enable swap partition. Visit the link below to learn more about the swap.
https://docs.nodebb.org/installing/os/ubuntu/#system-requirements