Self-hosted n8n on a small server: setup, backups and updates
A practical setup for self-hosted n8n on one small server: a Docker Compose file, Postgres, a reverse proxy for webhooks, backups you can restore and safe updates.

Running n8n on your own server is one of the better trades in small-team automation. You get unlimited workflow runs for the price of a modest virtual machine, your data stays on a box you control, and you can install community nodes without asking anyone. The cost is that you become the operations department. Nobody else will notice when the disk fills up, when the certificate fails to renew or when an update changes how a node behaves. This piece is the setup I use for clients with a handful of staff and a few dozen workflows, plus the chores that keep it healthy.
If you are still deciding between hosting it yourself and paying for a managed service, read n8n compared with Zapier first. Self-hosting only pays off when someone on the team is happy to own a server for the long run.
What you need before you start
The shopping list is short:
- A small Linux virtual machine. For a team running a few dozen light workflows, a machine with 2 GB of memory and a couple of virtual CPUs is a comfortable starting point. Workflows that handle large files or big batches of rows need more memory, so watch usage in the first weeks.
- A domain or subdomain you control, such as
automation.example.com, pointing at the server's IP address. - Docker and the Docker Compose plugin installed from the official Docker repositories for your distribution.
- An hour without interruptions, and a password manager for the secrets you are about to generate.
I count the setup at roughly 45 minutes for someone who has used Docker before, and about two hours for someone doing it the first time and reading every error message carefully. Both are fine. What matters is that the second person writes down what they did.
The Docker Compose file
n8n can store its data in SQLite inside its own volume, and for a single person testing it that is fine. For anything a business depends on, I use Postgres. It copes better with many executions, backups are a well-understood routine, and you can inspect the data with ordinary tools when something looks wrong.
Here is the Compose file. It runs three containers: Postgres, n8n and Caddy as the reverse proxy that handles HTTPS.
services:
postgres:
image: postgres:16
restart: unless-stopped
environment:
POSTGRES_USER: n8n
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: n8n
volumes:
- pg_data:/var/lib/postgresql/data
n8n:
image: docker.n8n.io/n8nio/n8n:${N8N_VERSION}
restart: unless-stopped
depends_on:
- postgres
env_file: .env
volumes:
- n8n_data:/home/node/.n8n
caddy:
image: caddy:2
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
volumes:
pg_data:
n8n_data:
caddy_data:
A few choices in there are deliberate. Only Caddy publishes ports to the outside world, so neither Postgres nor n8n's own port is reachable from the internet. The n8n image tag comes from a variable rather than a floating tag, which means an update happens when you change one line, not when the server restarts and pulls something new. The n8n_data volume holds n8n's settings folder, which matters for the encryption key discussed below.
The environment file
The .env file next to the Compose file holds the settings. Keep it out of any shared folder and readable only by the account that runs Docker.
N8N_VERSION=pin-a-specific-version-here
POSTGRES_PASSWORD=long-random-string
DB_TYPE=postgresdb
DB_POSTGRESDB_HOST=postgres
DB_POSTGRESDB_DATABASE=n8n
DB_POSTGRESDB_USER=n8n
DB_POSTGRESDB_PASSWORD=long-random-string
N8N_HOST=automation.example.com
N8N_PROTOCOL=https
WEBHOOK_URL=https://automation.example.com/
N8N_ENCRYPTION_KEY=another-long-random-string
N8N_PROXY_HOPS=1
GENERIC_TIMEZONE=Africa/Accra
TZ=Africa/Accra
Pick the version from n8n's release notes and write the exact number in place of the placeholder. The two Postgres passwords must match. Set the timezone to wherever your team works, because schedule triggers use it, and a nightly report that fires at 3 a.m. local time instead of midnight confuses people more than you would expect.
Check the official n8n documentation for the full list of environment variables before you rely on any of them. Names occasionally change between major versions, and the documentation is the source of truth.
Webhooks behind a reverse proxy
This is where most first installs go wrong. n8n builds the webhook URLs it shows you in the editor from its own settings. If it thinks it lives at http://localhost:5678, that is the address it will display, and the form tool or payment provider you paste it into will never reach you.
Two settings fix it. WEBHOOK_URL tells n8n the public address to use when it builds webhook URLs, and N8N_PROXY_HOPS tells it there is one proxy in front of it, so it trusts the forwarded headers for things like the client's IP address. The Caddyfile itself is tiny:
automation.example.com {
reverse_proxy n8n:5678
}
Caddy requests and renews a TLS certificate on its own, as long as the domain points at the server and ports 80 and 443 are open. If you prefer Nginx or Traefik, the idea is the same: terminate HTTPS at the proxy, forward to port 5678 on the internal Docker network, and pass the usual forwarded headers. The editor also keeps a live connection open to the server, so whatever proxy you use has to allow WebSocket upgrades. Caddy does that without extra configuration.
To test, create a workflow with a Webhook trigger, copy its production URL, activate the workflow and send it a request from your laptop:
curl -X POST https://automation.example.com/webhook/test-orders \
-H "Content-Type: application/json" \
-d '{"order_id": "A1001", "total": 42.5}'
If the execution appears in the workflow's history with that JSON in it, the proxy, certificate and webhook settings are all correct. If you get a 404, check whether you used the test URL (which only listens while the editor is waiting) instead of the production one.
Credentials and the encryption key
n8n encrypts the credentials you save (API keys, OAuth tokens, database passwords) with an encryption key. If you do not set one, n8n generates a key on first start and stores it in its settings folder inside the n8n_data volume. That works until the day you rebuild the server from a database backup without that volume, and every saved credential becomes unreadable.
So set N8N_ENCRYPTION_KEY yourself, as in the file above, and store a copy in the password manager. Treat it like the master key it is. Anyone with the key and a database dump can decrypt every credential you have saved.
A few habits keep credentials manageable:
- Create one n8n user per person instead of sharing a login, so you can see who changed what.
- Name credentials after the account and its purpose, such as "Xero, read only, finance reports", rather than "Xero 2".
- Give each service the narrowest permission that still works. A workflow that only reads orders does not need a key that can issue refunds.
- When someone leaves, rotate the keys they could see, not just their n8n login.
Backups you can actually restore
A backup you have never restored is a hope, not a backup. I back up three things:
- The Postgres database, which holds workflows, credentials (encrypted) and execution history.
- The
.envfile and the Caddyfile, which are small but annoying to recreate. - A separate export of workflows as JSON, which is handy for reviewing changes and moving single workflows between instances.
This script runs nightly from cron on the server. It dumps the database, exports workflows through n8n's own command line, and keeps two weeks of files.
#!/usr/bin/env bash
set -euo pipefail
cd /opt/n8n
STAMP=$(date +%F)
DEST=/opt/backups/n8n
mkdir -p "$DEST"
docker compose exec -T postgres pg_dump -U n8n -d n8n | gzip > "$DEST/db-$STAMP.sql.gz"
docker compose exec -T n8n n8n export:workflow --all --output=/home/node/.n8n/workflows.json
docker compose cp n8n:/home/node/.n8n/workflows.json "$DEST/workflows-$STAMP.json"
cp .env Caddyfile "$DEST/"
find "$DEST" -name "*.gz" -mtime +14 -delete
find "$DEST" -name "workflows-*.json" -mtime +14 -delete
Files sitting on the same server are not a backup on their own, so copy the folder somewhere else afterwards with whatever off-site storage you already pay for. Encrypt it on the way, since the .env file contains the encryption key.
Then, once a quarter, do a restore drill. Spin up a throwaway virtual machine, copy the Compose file and .env across, start Postgres alone, load the dump with psql, then start n8n and open a workflow that uses a saved credential. If the credential works, your backups are real. The first drill usually takes an hour and turns up at least one missing step. Write that step into the runbook.
Keeping execution data from filling the disk
Every workflow run is saved with its input and output by default. For a workflow that polls an inbox every minute, that adds up quickly. I have seen a small server's disk fill in a couple of months because nobody turned this down.
n8n has settings to prune old execution data automatically and to choose which runs are saved at all, for example keeping failed runs but skipping successful ones for chatty workflows. Look up the execution data pruning options in the documentation and set them to something like "keep a couple of weeks" from day one. Also add a simple disk usage alert, even if it is only a daily cron job that emails you when the disk passes 80 percent.
Updating without drama
n8n releases often. Most updates are uneventful, but some change node behaviour or require a database migration that runs on start. My routine takes about 20 minutes:
- Read the release notes between your pinned version and the target, paying attention to anything marked as breaking.
- Run the backup script by hand, so you have a dump from minutes before the update.
- Change
N8N_VERSIONin.envto the new version. - Run
docker compose pull n8nand thendocker compose up -d n8n. - Watch the logs with
docker compose logs -f n8nuntil it reports that the editor is reachable. - Open the three or four workflows the business would notice first and run them manually or check their next executions.
If something breaks, roll back by restoring the dump you just took and setting the old version again. Rolling back the version alone is not enough after a database migration, which is why the backup in step 2 is not optional.
Update the operating system and Docker on the same calendar, and do not leave n8n many versions behind. Jumping across a long gap means reading a long stack of release notes at once and dealing with several breaking changes in one sitting.
A worked example: one small office's setup
A seven-person property management office I helped runs 23 workflows on a 2 GB server: tenant enquiries from a web form into their ticket tool, nightly rent reconciliation from a bank export, and reminders for lease renewals. Their numbers, roughly:
| Task | Before | After |
|---|---|---|
| Copying form enquiries into tickets | About 40 minutes a day | None, checked weekly |
| Rent reconciliation | Half a day each month | 30 minutes of review |
| Server care | None | About 1 hour a month |
That last row is the honest part. The hour a month covers updates, a glance at failed executions and the quarterly restore drill. If nobody on the team will commit to that hour, a hosted plan is the better choice, and there is no shame in it. The automation section has more on choosing between tools when the server work is the deciding factor.
Questions people ask
Is SQLite really not good enough?
For one person experimenting, it is fine. For a team, I prefer Postgres because backups and restores are routine and it holds up better under many executions. Moving from SQLite to Postgres later is possible but fiddly, so start with Postgres if you expect the instance to matter.
Do I need queue mode?
Probably not at first. Queue mode splits work across separate worker processes and needs Redis. It helps when you run many heavy executions in parallel. A small team with a few dozen workflows rarely needs it, and it adds moving parts you then have to maintain.
Can I put n8n behind a login page or VPN?
You can protect the editor that way, but webhook URLs must stay reachable by the services that call them. If you restrict access, make sure the /webhook/ paths are excluded, then test with the curl command above from outside your network.
Before you invite the rest of the team, run one restore drill on a spare machine. If it works, write the date on the runbook and book the next one.
Stacks: Automation & Internal Tools
More from this stack

Automation & Internal Tools
Appsmith vs Retool (and Budibase) for internal tools

Automation & Internal Tools
Make vs Zapier: visual scenarios or simple zaps

No-Code & Low-Code
NocoDB and other Airtable alternatives you can self-host