Quick Guide: Node-RED with Free HTTPS on Oracle Cloud
Published: 2023-05-22 18:42:34

If you're looking for a simple way to install Node-RED on a server exposed in HTTPS for free, you've come to the right place! In this article, I will guide you through the necessary steps to properly set up your environment. Using HTTPS not only provides increased security but also enables OAuth flows that require a secure return URL.

## Step 1: Creating the Oracle Linux Machine with Free Tier Access

To install Node-RED we take advantage of the Free Tier offering by Oracle Cloud, which provides access to some virtual machines at no cost.

During the creation process, make sure to provide a unique name for your instance, as it will help you identify it later. You'll also have the opportunity to select the desired configuration options, such as the availability domain and instance shape. It's important to note that the Free Tier offers specific shape options.

As part of the setup, you'll need to download the SSH key pair, which ensures secure access to your machine. Follow the provided instructions to download the key pair file. This key will be used for SSH access to your Oracle Linux machine.

## Step 2: Enabling Ingress Rules for Ports 80 and 443

Access the Oracle Cloud control panel and enable the ingress rules for ports 80 and 443 on the subnet you're using for your machine. This will allow you to access your Node-RED application through HTTP and HTTPS protocols.

## Step 3: Creating a DDNS Record

To have a custom domain name for your Oracle Cloud server, create a DDNS record using a service like https://www.noip.com/. These services usualy offer custom third level domains for free.

## Step 4: Connect to your instance

```
chmod 600 ssh-key-2023-05-23.key
ssh -i ssh-key-2023-05-23.key opc@testcamp.ddns.net
```

## Step 5: Setting Up the HTTPS Certificate
Start by installing Certbot, a widely used tool for managing SSL/TLS certificates. Follow these commands:

```
sudo yum --disablerepo=* --enablerepo=ol8_developer_EPEL install -y snapd
sudo systemctl start snapd.service
sudo ln -s /var/lib/snapd/snap /snap
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
```
Next, open the firewall for ports 80 and 443:

```
sudo firewall-cmd --permanent --zone=public --add-port=80/tcp
sudo firewall-cmd --reload
```
Now, run the command to obtain the certificate using Certbot:

```
sudo certbot certonly --standalone
sudo chmod -R 2755 /etc/letsencrypt
```

## Step 5: Setting Up Node-RED

Now that you have your HTTPS certificate, you can proceed with installing Node-RED. Use the following command:

```
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/rpm/update-nodejs-and-nodered)
```
Next, redirect requests on port 443 to the Node-RED port (1880) with the following command:

```
sudo iptables -t nat -I PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 1880
```
Now, open the Node-RED configuration file using a text editor:

```
sudo vim /home/nodered/.node-red/settings.js
```
Inside the file, look for the https section and add the path to your newly obtained certificates:

```
https: {
  key: require("fs").readFileSync('/etc/letsencrypt/live/testcamp.ddns.net/privkey.pem'),
  cert: require("fs").readFileSync('/etc/letsencrypt/live/testcamp.ddns.net/cert.pem')
},
```
Save the file and restart Node-RED with the following command:

```
sudo systemctl restart nodered
```

## Conclusions
Congratulations! You have successfully installed Node-RED on an Oracle Cloud server using the Free Tier access. This serves as a great starting point to explore the capabilities of Node-RED and develop your applications.

While you have completed the essential steps outlined in this article, it's important to note that there may be additional steps or improvements that can be made based on your specific requirements. Consider exploring further documentation and resources to enhance the security, performance, and functionality of your Node-RED installation.