Migrating a Miniflux instance from a public VPS to a personal Tailscale host

https://xpil.eu/gZLkd

Introduction

I started experimenting with Tailscale a couple of weeks ago. So far, it’s been stable and uneventful, which gave me the confidence to migrate my Miniflux instance from a public VPS to a local host accessible only via Tailscale. The reasons? Cost savings, better control, improved network security - and most importantly, I am a tinkerer, and this mini-project offers plenty of that. 😊

This article outlines the steps for migrating Miniflux from a public VPS to a local Tailscale-connected machine. Be aware though, it is very specific to my highly personalized setup, so your milage may (and most certainly will) vary.

Prerequisites

  1. Existing Miniflux Setup on a public VPS.
  2. Tailscale Network with both the VPS and local host connected (ideally using passwordless ssh).
  3. Personal Host, e.g., Ubuntu Server.
  4. Restic Backup Repository (optional but recommended).

Step 1: Preparing the Personal Host

Update the System:

sudo apt update && sudo apt upgrade -y

Install Dependencies:

sudo apt install -y postgresql nginx wget curl tar

Enable Tailscale:

tailscale up

(here, you will be asked to authenticate in your Tailscale network)

Step 2: Set Up PostgreSQL

Create the Database and User:

sudo -i -u postgres
createdb miniflux
psql -c "CREATE USER miniflux WITH ENCRYPTED PASSWORD '<password>';"
psql -c "GRANT ALL PRIVILEGES ON DATABASE miniflux TO miniflux;"
exit

Step 3: Transfer and Restore the Database

Retrieve Backup from the VPS:

If using Restic, mount the repository:

restic -r <restic-repo-location> mount /mnt/restic

Copy the Database Dump:

cp /mnt/restic/path/to/miniflux.sql.gz ~/miniflux.sql.gz
gunzip ~/miniflux.sql.gz

Restore the Database:

psql -U miniflux -d miniflux -f ~/miniflux.sql

Step 4: Install and Configure Miniflux

Install Miniflux:

(follow instructions for your target environment)

Create a Configuration File:

nano ~/miniflux.env

Add the following:

DATABASE_URL=postgres://miniflux:<password>@127.0.0.1:5432/miniflux?sslmode=disable
LISTEN_ADDR=0.0.0.0:8080
BASE_URL=http://<hostname>/miniflux

Step 5: Run Miniflux as a Service

(I am using systemd, if you're on upstart or openrc or sysvinit or anything else, this isn't going to work for you)

Create a Systemd Service File:

sudo nano /etc/systemd/system/miniflux.service

Add the following:

[Unit]
Description=Miniflux RSS Reader
After=network.target

[Service]
User=<user>
Group=<user>
EnvironmentFile=/home/<user>/miniflux.env
ExecStart=/usr/local/bin/miniflux
Restart=on-failure

[Install]
WantedBy=multi-user.target

Enable and Start the Service:

sudo systemctl daemon-reload
sudo systemctl enable miniflux
sudo systemctl start miniflux

Step 6: Configure Nginx

In order for your Miniflux to be accessible under http://your-tailscale-host/miniflux rather than http:/your-tailscale-host:8080, a web proxy needs to be configured - I am using nginx since it's the most popular choice.

Create an Nginx Configuration:

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

Add the following:

server {
    listen 80;
    server_name <hostname>;

    location /miniflux/ {
        proxy_pass http://127.0.0.1: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;
        proxy_set_header X-Forwarded-Proto $scheme;

        sub_filter_once off;
        sub_filter 'href="/' 'href="/miniflux/';
        sub_filter 'src="/' 'src="/miniflux/';
    }

    location = / {
        return 301 /miniflux/;
    }
}

Enable and Reload Nginx:

sudo ln -s /etc/nginx/sites-available/miniflux /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Step 7: Automate Backups

This is an optional step but a backup is a backup, having one never hurts, unlike the opposite. I am using Restic because it's the "fire-and-forget" solution that simply works. It saved my puny ass so many times, I learned to trust it.

Set Up Restic Backup Script:

nano ~/restic-backup.sh

Add the following:

export RESTIC_REPOSITORY=rclone:dbx:restic-repo
export RESTIC_PASSWORD=<password>

DB_BACKUP_PATH=/home/<user>/backups/databases
mkdir -p $DB_BACKUP_PATH
pg_dump -U miniflux -d miniflux | gzip > $DB_BACKUP_PATH/miniflux.gz

restic backup $DB_BACKUP_PATH
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6
restic check

(note: I am using Dropbox backend via rclone, YMMV)

Make the script executable:

chmod +x ~/restic-backup.sh

Add to Cron:

crontab -e

Schedule the script to run daily at 2 AM:

0 2 * * * /home/<user>/restic-backup.sh >> /home/<user>/restic-backup.log 2>&1

And... Bob's your uncle!

You should now be able to use your Miniflux instance via Tailscale, using the following url: http://<your tailscale host name>/miniflux


Next steps

Once you’ve been using your new Miniflux instance for a while, it’s time to shut down the old one. I prefer a phased approach: disable it first, wait a few days or weeks to ensure there are no nasty surprises, and then remove it.

Disable old Miniflux instance:

SSH into the VPS and run:

sudo systemctl stop miniflux
sudo systemctl disable miniflux

Finally, remove it:

Ssh to the instance, then:

sudo apt remove miniflux

And now Bob is even more of an uncle than before!

https://xpil.eu/gZLkd

Leave a Comment

Komentarze mile widziane.

Jeżeli chcesz do komentarza wstawić kod, użyj składni:
[code]
tutaj wstaw swój kod
[/code]

Jeżeli zrobisz literówkę lub zmienisz zdanie, możesz edytować komentarz po jego zatwierdzeniu.