Organize Your Thoughts with Trilium - A Free, Open-Source Solution

Organize Your Thoughts with Trilium - A Free, Open-Source Solution

Sunny Sun Lv4

Complete Guide on Install and Configure Trilium Notes App using Nginx, Docker, and Oracle Cloud

Feeling overwhelmed by scattered notes and too much information? Try Trilium , a powerful open-source tool that helps you organize and connect your thoughts. With its flexible structure and impressive features, Trilium is more than just a note-taking app; it’s your personal knowledge management system.

This article will explore how to install and configure trilium notes step by step.

overview

Trilium provides a rich set of out-of-box features. Its hierarchical structure, rich text editing, and robust search capabilities make it an ideal platform for organizing information, taking notes, and capturing ideas. With features like code highlighting, mind mapping, and customizable templates, Trilium offers a versatile workspace for students, researchers, and knowledge workers alike.

Trilium can be installed on a desktop or on your own server. The most common approach is to use Docker to set up the App on a cloud VM so you can access it from anywhere. There are 3rd party paid services to host a Trilium instance for you and some free options.

Let’s walk through the process of hosting it on an Oracle always free VM instance .

Oracle forever free VM

Oracle Cloud offers a generous “Forever Free” program, providing users with access to a range of cloud services at no cost. This includes the ability to spin up free virtual machines for development and testing purposes. With specific limitations on CPU, memory, and storage, these free VMs are ideal for small-scale projects, learning, and experimentation.

Recently, I migrated a MySQL server to Oracle forever-free VM. The free ARM-based VM has three core CPUs and 18 G memory, and its current CPU and memory utilization is very low, as shown below.

low usage

Its remaining capability is more than enough to host a Trilium App.

Let’s do it.

Install the App on Docker

Firstly, we need to install docker on the Oracle VM. I won’t go through the process in detail, as it is described on the official Docker site . Below are the essential commands for the installation.

1
2
3
4
sudo apt-get update  
sudo apt install docker-ce
docker --version # check version
sudo docker run hello-world # test the installation

Now we can pull the Trilium docker image and run it as below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sudo docker pull zadam/trilium:0.58.7   
### create a data directory for trilium
sudo mkdir trilium-data

#run it locally
sudo docker run -d -t -i -p 127.0.0.1:8080:8080 -v ~/trilium-data:/home/trilium/data zadam/trilium:0.58.7

### test it
sudo docker ps
curl 127.0.0.1:8080
### stop the local run
sudo docker stop beautiful_bose

### run it and open to any ips
sudo docker run -d -p 0.0.0.0:8080:8080 -v ~/trilium-data:/home/trilium/data zadam/trilium:0.58.7

In the above commands, the following actions are performed

  • The trilium image version 0.58.7 (the latest available at the time of writing) is pulled.
  • The data volume is mapped to the /trilium-data directory on the host machine
  • The Docker port is mapped to port 8080 on the host machine
  • Access to the app is allowed from any IP address

As you can see, it is pretty straightforward to run a trilium app with Docker.

If you test the new instance from your browser using the URL:[http://[IP](http://[ip/) address]:8080, the setup screen should be shown.

trilium setup page

Secure the App with Ngnix and SSL certificate.

The next step is to secure the App, make it accessible behind a reverse proxy and install an SSL certificate to protect the communication between the browser and the server.

Firstly, let’s install the Nginx server.

1
2
3
4
5
sudo apt install nginx # install  

sudo service nginx start #start

sudo service nginx status # verify the nginx status

We can verify that the new instance is listening to port 80.

1
sudo netstat -tulpn

Nginx listening port 80

Once Nginx is installed, a free Let’s Encrypt SSL certificate can be created, and the appropriate configuration can be added to Nginx.

1
2
3
4
5
sudo apt-get install certbot  
sudo apt-get install python3-certbot-nginx

#request certificate for notes.xxx.com
sudo certbot --nginx -d [your domain name]

To set up the auto-renew of the certificate:

1
2
3
4
#setup auto renew certificate  
sudo crontab -e
### add the following line
0 12 * * * /usr/bin/certbot renew --quiet

If you own a domain name, you can set up a sub domain for your new Trilium app. For example, create an A record fornotes.xxx.com, and map it to your VM IP address. This will allow you to access the URL [https://notes.xxx.com](https://notes.xxx.com/) in the browser.

default Nginx

The final step is to configure the redirect in the Nginx. The Nginx configuration file can typically be found in either /etc/nginx/nginx.conf or /etc/nginx/sites-enabled/default. The default setting is something like the one below.

1
2
3
4
5
6
7
server_name notes.xxx.com; # managed by Certbot  

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

The location section needs to be updated as below, so the request to port 443 will be directed to port 8080 at the VM.

1
2
3
location / {  
proxy_pass http://localhost:8080;
}

To make the change effective, we should restart Nginx. Then, you can enjoy the new App instance by accessing https://notes.xxx.com.

Trilium is working

Troubleshooting: Notes don’t refresh

If you got an issue where refreshing the browser is necessary to view changes in Trillium Notes, It may be caused by the missing nginx proxy setting to support the web socket.

To determine whether it is the cause, open the Chrome dev tools, to check for the below error is shown.

To fix the issue, log in to the server and update Nginx config file as follows:

1
2
3
4
5
6
location / {  
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

After the update, don’t forget to restart the Ngnix server.

Installing Multiple Trilium Instances on a Single VM

Installing multiple instances of Trilium on a single VM requires careful isolation to prevent conflicts between the instances. This can be achieved through a combination of virtual environments and directory structures.

  1. Create Isolated Environments:
    Virtual Environments: Use tools like virtualenv (Python) or conda to create separate environments for each Trilium instance. This ensures that dependencies and configurations are isolated.
    User Accounts: Consider creating separate user accounts on the VM for each Trilium instance. This provides additional isolation at the operating system level.

  2. Install Trilium in Separate Directories:
    Create dedicated directories for each Trilium instance.
    Install Trilium within these directories, ensuring no overlap in configuration or data files.

  3. Configure Database Connections:
    If using a database for Trilium, configure each instance to use a separate database or database user. This prevents data conflicts.

  4. Port Configuration:
    Assign different port numbers to each Trilium instance to avoid conflicts when accessing them through a web browser.

Conclusion

Trilium is a great note-taking App. It is lightweight, able to work offline, fast, and works well on a mobile browser.
I hope you find this post useful. Happy noting!

  • Title: Organize Your Thoughts with Trilium - A Free, Open-Source Solution
  • Author: Sunny Sun
  • Created at : 2023-02-12 00:00:00
  • Updated at : 2024-07-28 21:11:18
  • Link: http://coffeethinkcode.com/2023/02/12/organize-your-thoughts-with-trilium/
  • License: This work is licensed under CC BY-NC-SA 4.0.