Skip to main content

Self-hosting

This page covers running a ListThingy server for other people over the internet. It assumes you have installed the server and read Configuration.

Add HTTPS​

The stack speaks plain HTTP. Put a reverse proxy in front of it to serve HTTPS. Caddy fetches a certificate on its own and needs three lines of config.

Move ListThingy off port 80 so Caddy can have it, and tell ListThingy to trust the proxy. Add this to .env:

PORT=8080
TRUSTED_PROXIES=172.16.0.0/12

Trust your proxy explains the TRUSTED_PROXIES line.

Then give Caddy this Caddyfile, with your own domain:

lists.example.com {
reverse_proxy localhost:8080
}

Caddy passes WebSocket connections through and sets X-Forwarded-For with no extra config. Any other proxy works if it does the same. In Nginx that takes these lines inside your server block:

location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /ws/ {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 300s;
}

Stop PIN guessing​

ListThingy blocks an address from a list after too many wrong PINs. See Wrong guesses. It does not ban addresses from the whole server. Use fail2ban or a similar tool for that.

Every unlock attempt appears in the web access log with the visitor's address. Failed attempts end in 401, 403 or 429. To write the log to a file on the host, create docker-compose.override.yml next to docker-compose.yml:

services:
web:
volumes:
- ./logs:/var/log/nginx

Run docker compose up -d. The log appears at logs/access.log. Rotate it with logrotate and the copytruncate option, since nginx keeps the file open.

Then give fail2ban a filter in /etc/fail2ban/filter.d/listthingy.conf:

[Definition]
failregex = ^<HOST> .* "POST /v1/lists/[0-9a-f]+/unlock HTTP/[0-9.]+" (401|403|429)

And a jail in /etc/fail2ban/jail.d/listthingy.conf, with the path to your log:

[listthingy]
enabled = true
filter = listthingy
logpath = /opt/listthingy-api/logs/access.log
maxretry = 10
findtime = 1h
bantime = 1d

If Caddy or another proxy runs on the host, the default ban action works. If visitors reach Docker's port directly, add chain = DOCKER-USER to the jail. Docker's own firewall rules skip the default chain.

Back up your lists​

All data lives in one SQLite file inside the db-data volume. Docker names the volume after the project folder, such as listthingy-api_db-data. Removing that volume deletes every list, so never run docker compose down -v unless you mean it.

Take a backup while the server runs. The first command writes a safe copy inside the container. The second copies it out. The third cleans up.

docker compose exec api sqlite3 /var/www/api/db/database.sqlite ".backup /var/www/api/db/backup.sqlite"
docker compose cp api:/var/www/api/db/backup.sqlite ./listthingy-backup.sqlite
docker compose exec api rm /var/www/api/db/backup.sqlite

Do not copy database.sqlite straight out of a running container. The database keeps recent writes in a separate log file, and a plain copy can miss them.

To restore a backup, copy it in and load it:

docker compose cp ./listthingy-backup.sqlite api:/var/www/api/db/restore.sqlite
docker compose exec api sqlite3 /var/www/api/db/database.sqlite ".restore /var/www/api/db/restore.sqlite"
docker compose exec api rm /var/www/api/db/restore.sqlite

The restore replaces every list on the server with the lists in the backup.

Update​

Pull the new code and rebuild:

git pull
docker compose up -d --build

Your data stays in its volume through the rebuild. The API applies any new database changes on the first request after it starts.

Logs​

The web service logs every request. Watch them arrive:

docker compose logs -f web

If you write the log to a file for fail2ban, requests go to logs/access.log and errors to logs/error.log instead.