Chapter 7 · 7.3
n8n: automation on your own server
With n8n you connect services and automate tasks, for example a form that adds a row to a spreadsheet and sends a message. Your workflows and data stay on your own server.
Each recipe builds on the working folder /srv/diensten with Caddy from Your working folder with compose.yaml, .env and Caddy. You add a service to compose.yaml, a block to the Caddyfile, and an A and AAAA record for the name (see A and AAAA records in My Domains).
1. DNS
Create an A and AAAA record for n8n.example.com.
2. compose.yaml
n8n:
image: n8nio/n8n
restart: unless-stopped
environment:
N8N_HOST: "n8n.example.com"
N8N_PORT: "5678"
N8N_PROTOCOL: "https"
N8N_WEBHOOK_URL: "https://n8n.example.com/"
NODE_ENV: "production"
GENERIC_TIMEZONE: "Europe/Amsterdam"
TZ: "Europe/Amsterdam"
volumes:
- n8n-data:/home/node/.n8n
And under volumes::
n8n-data:
N8N_WEBHOOK_URL exists from n8n 2.30.0 onwards. If you use an older version, it is called WEBHOOK_URL. n8n uses this address to create the links for webhooks; if it is wrong, your webhooks won't work from outside.
3. Caddyfile
n8n.example.com {
reverse_proxy n8n:5678
}
anna@web1:/srv/diensten$ sudo docker compose up -d
anna@web1:/srv/diensten$ sudo docker compose exec -w /etc/caddy caddy caddy reload
Open https://n8n.example.com and create the owner account straight away. n8n only works over https; Caddy takes care of that.
Backup
The volume n8n-data holds your workflows, your login details for other services and the key n8n uses to encrypt those login details. Without that key, you can no longer use a backup. So include the complete volume in your backup (see Backing up databases and Docker volumes properly).
Please note: A workflow can do a lot: send emails, read files, control other services. Only give it the permissions it needs, and protect your n8n account with a strong password and two-step verification.
