Oct 4, 2024 3 min read

Trilium Notes: Self-Hosting Made Simple

Trilium Notes: Self-Hosting Made Simple
Table of Contents

Trilium Notes is a powerful, self-hosted hierarchical note-taking application designed for users who value customization, privacy, and control over their data. With features like rich formatting, robust API support, and seamless synchronization, it’s an excellent choice for developers and tech-savvy users who want a tailored knowledge management system. In this guide, we’ll cover how to install, configure, and manage Trilium Notes, along with advanced features to help you get the most out of the app.

Installing Trilium Notes

πŸ“¦ Docker/Docker Compose Setup

Docker is the easiest and most effective way to deploy Trilium Notes. Below is a docker-compose.yml configuration tailored to Trilium Notes:


version: "3.8"

services:

trilium:

image: zadam/trilium:latest

container_name: trilium_notes

ports:

- "8080:8080" # Map Trilium's internal port to the host machine

volumes:

- ./trilium-data:/root/trilium-data # Persistent storage for Trilium data

environment:

- TRILIUM_DATA_DIR=/root/trilium-data # Set the Trilium data directory

restart: unless-stopped

To deploy Trilium Notes with this setup, run the following commands:


mkdir trilium && cd trilium

nano docker-compose.yml # Paste the YAML content above

docker-compose up -d

This will pull the latest Trilium Notes image, create the necessary containers, and start the application.

πŸš€ Manual Installation

To install Trilium Notes manually on a Linux server, follow these steps:

  1. Install dependencies:

sudo apt update && sudo apt install -y wget unzip nodejs npm

  1. Download and extract Trilium Notes binaries:

wget https://github.com/zadam/trilium/releases/latest/download/trilium-linux-x64-server.zip

unzip trilium-linux-x64-server.zip -d trilium

cd trilium

  1. Start the application:

./trilium.sh

By default, Trilium Notes will be accessible on port 8080. You should configure your firewall accordingly to allow external access.

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

To serve Trilium Notes via Nginx, create a server block configuration file:


sudo nano /etc/nginx/sites-available/trilium

Add the following content:


server {

listen 80;

server_name yourdomain.com;

location / {

proxy_pass http://localhost:8080;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

Enable the configuration and restart Nginx:


sudo ln -s /etc/nginx/sites-available/trilium /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl restart nginx

πŸ”’ SSL/TLS Setup

Secure your Trilium Notes instance using Let's Encrypt:


sudo apt install -y certbot python3-certbot-nginx

sudo certbot --nginx -d yourdomain.com

This command automatically configures SSL and sets up certificate renewals.

πŸ› οΈ Testing and Reloading Nginx

Verify that your configuration works:


sudo nginx -t && sudo systemctl reload nginx

Visit https://yourdomain.com to confirm Trilium Notes is served securely.

Logging and Debugging Trilium Notes

πŸ—ƒοΈ Enabling Debug Logs

Modify the Trilium Notes configuration to enable debug logging. If using Docker, add the environment variable:


environment:

- LOG_LEVEL=debug

Restart the container:


docker-compose restart trilium

πŸ“„ Viewing Logs

For Docker deployments:


docker logs trilium_notes

For manual installations, logs are available in the application directory:


cat trilium-data/logs/latest.log

πŸ› οΈ Troubleshooting Common Issues

Common issues like port conflicts or database errors can often be resolved by inspecting logs. Use grep to filter specific errors:


docker logs trilium_notes | grep "ERROR"

πŸ“€ Exporting Logs

To integrate with an external logging system, redirect logs to a file:


docker logs trilium_notes > /var/log/trilium.log

You can then set up a log shipper (like Filebeat) to forward logs to an ELK stack for analysis.

Backup and Restore

πŸ—‚οΈ File-Based Backups

To back up your Trilium Notes data directory:


tar -czvf trilium-backup-$(date +%F).tar.gz trilium-data/

πŸ”„ Database Backups

If you're using an external database, use the database-specific tools (e.g., mysqldump for MySQL).

πŸ“… Automated Backup Scripts

Create a cron job for periodic backups:


crontab -e

Add the following line:


0 2 * * * tar -czvf /backup/trilium-backup-$(date +\%F).tar.gz /path/to/trilium-data/

Updating and Upgrading Trilium Notes

⬆️ Updating Docker Images

To update the Docker container:


docker-compose pull trilium

docker-compose up -d

πŸ› οΈ Manual Updates

For manual installations, download the latest release and replace the existing binaries:


wget https://github.com/zadam/trilium/releases/latest/download/trilium-linux-x64-server.zip

unzip -o trilium-linux-x64-server.zip -d trilium

Restart the application:


./trilium.sh

πŸ” Checking for Updates

Check for updates on the Trilium Notes GitHub Releases page.

Leveraging Trilium Notes’s Unique Features

πŸ”§ Enabling APIs

Enable the Trilium Notes API by setting the API_AUTH_TOKEN environment variable:

For Docker:


environment:

- API_AUTH_TOKEN=your-secure-token

For manual installations:


export API_AUTH_TOKEN=your-secure-token

./trilium.sh

Access the API with a token:


curl -H "Authorization: Bearer your-secure-token" http://localhost:8080/api/notes

🌟 Advanced Configurations

Customize Trilium Notes using environment variables such as:

  • BASE_PATH: Set a custom base URL.

  • DATA_DIR: Specify an alternate data directory.

Example for Docker:


environment:

- BASE_PATH=/notes

Restart the container for changes to take effect.

Wrapping Up

In this guide, we covered how to deploy, configure, and manage a self-hosted instance of Trilium Notes, along with leveraging its advanced features. Trilium Notes provides a flexible and powerful environment for knowledge management, giving you full control over your data. Start experimenting with these configurations today to unlock the app’s potential for your workflows!

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.