Site Logo
mnjm

Trilium Notes - Hosting it in Oracle Cloud

Posted on 7 mins

Hosting Nginx

Are you looking for a note taking app that can be self hosted? Allow me to introduce Trilium Notes

Trilium Notes

Trilium Notes is an open-source hierarchical note-taking app designed as a web app using Electron. It is available both as a desktop app (for Windows and Linux) and as a self-hosted web app.

Trilium Notes checks all the right boxes in terms of features, including, but not limited to, rich WYSIWYG note editing, support for tables, math, Markdown integration, code highlighting, note link maps, note-level encryption support, versioning, canvas support, Mermaid Diagram, and many more. Sounds awesome, right?

bfd6a1146fea843206931bd1c797b2e1.png

So, let’s dive into hosting it on Oracle Cloud and setting up sync with a desktop app.

Hosting Trilium on Oracle’s Free Forever VM

1 Oracle Account Setup

At the time of writing this guide, Oracle offers a generous Free Tier cloud service claimed to be ‘Free Forever.’ There are two different configurations under this tier:

  1. 2 x AMD Single Core Compute VMs with 1 Gig RAM
  2. 1 x ARM Ampere A1 Compute VM with 3000 CPU hours.

For this guide, I’ll be using the AMD 1 x Core 1Gig Instance. You can also opt for the latter option for more performance. If you don’t have a free Oracle “Free Forever” Cloud account, create one from here . You’ll need a Credit Card to signup for verification.

2 Create VM Instance

3 Pull and Run Trilium Docker Image

sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce -y

c1304b5f1e93bff466b46d95975d34ab.png

version: '3'
services:
  trilium:
    ports:
      - '8080:8080'
    volumes:
      - './trilium-data:/home/node/trilium-data'
    image: 'zadam/trilium:0.63-latest'
    restart: unless-stopped

d3cd9d5df3853d15ed528476309c8b5b.png

262b8245720a2148aa877d9f26a50ae3.png

4 Setup a subdomain and Enable HTTPS

Obtain a new subdomain from any of the domains you own and add a DNS record to point that subdomain to the VM’s IP. Refer to your domain provider’s help section for guidance; it should be free of cost.

4.1 Setup nginx on Ubuntu VM

server {
    listen 80;
    listen [::]:80;

    server_name trilium.example.net; #change trilium.example.net to your domain without HTTPS or HTTP.
    location / {
        proxy_set_header Host $host;
        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 Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://127.0.0.1:8080; # change it to a different port if non-default is used
        proxy_read_timeout 90;
    }
}

4.2 Expose HTTP port (80) and SSL port (443)

Oracle, by default, creates a Virtual Cloud Network (VCN) with all your instances and machines connected. This VCN is protected by a firewall that doesn’t allow traffic to and from unknown ports, including ports 80 and 443. An ingress rule needs to be added to allow traffic on these ports. Follow the below steps:

  1. Go to your Instance page in Oracle Cloud and click on the subnet link under ‘Instance Information’.

Oracle Cloud Ubuntu Instance a.jpg

  1. From there. click on the default security list

Oracle Cloud Ubuntu Instance a.png

  1. Add a new Ingress Rule

    • with Source CIDR 0.0.0.0/0
    • IP Protocol TCP
    • Destination Port Range 80
    • And Description HTTP

1_Oracle Cloud Ubuntu Instance a.png

  1. Add another Ingress Rule with the port range set as 443 and SSL as the description by following the step mentioned above.

Now expose ports 80 and 443 in Ubuntu’s firewall by running the following commands:

sudo iptables -I INPUT -p tcp --dport 80 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -I OUTPUT -p tcp --sport 80 -m conntrack --ctstate ESTABLISHED -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 443 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -I OUTPUT -p tcp --sport 443 -m conntrack --ctstate ESTABLISHED -j ACCEPT

Now you should be able to use curl and get a response from your local machine - curl -L <instance-ip>

4.3 Enabling HTTPs using Certbot

Certbot is a client that fetches and deploys SSL certificates from Let’s Encrypt and other ACME-compliant CAs to your web server. It also automatically generates new certificates upon expiration. We will use the default Let’s Encrypt CA to generate an SSL certificate.

sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
Now, the Trilium server should be up and accessible through your browser with HTTPS.

5 Trilium Account Setup

ecdcd27e212f7209681fcc73e3e8cdec.png

22b8358c422d8191ececb36998e95421.png

842ec53ba78069dbcaee894ab3cc22b3.png

Now you take notes using this Trilium server from everywhere!

Now lets install Trilium Desktop and sync it with the server

Trilium Desktop App

1 Installation

1.1 On Windows

1.2 On Ubuntu and Debian Distro

1.3 On Non-Debian Distros

2 Syncing it with the server

ad28ae24dc782d01f67f8b82c7a664a5.png

af6032dc92814b28e67ab0768fea01d5.png

That’s it! Your Trilium Desktop app should sync up with the server.

9eb61aaf7ec03ec7216edabd39a290d8.png

References