n8n Automation on a VPS: First Workflows, Setup and Backups

Published on | Updated

Run n8n automations on your own VPS: pick the first workflows, pin the Docker image, put webhooks behind a proxy, guard the encryption key and back it all up.

A technician with a tablet in a data center aisle between rows of server racks

You want your automations on a server you control, and you picked n8n. Next come practical questions: which workflows first, how to run n8n so updates never surprise you, how webhooks reach it over HTTPS, what protects your saved logins, when queue mode pays off and what to back up. This guide answers them in order, with a Docker Compose setup for Ubuntu 24.04 and Debian 12 based on n8n's examples.

Quick answer: Start with an error workflow, a scheduled report and a webhook intake. Run n8n with Docker Compose next to Postgres and a task runner container, with the version pinned in .env (2.45.7 was the stable release on 31 October 2026) and port 5678 bound to 127.0.0.1. Put Caddy or Nginx in front with N8N_WEBHOOK_URL and N8N_PROXY_HOPS=1 set, publish workflows to make them live, back up the encryption key with the database, and add queue mode only when one process can't keep up.

What to Automate First

Pick workflows with one trigger, a few steps and a result you can check:

  1. An error workflow. Build it first: a workflow that starts with the Error Trigger node runs when a linked workflow fails, though only for automatic runs, not manual tests. Our monitoring guide builds one with email, Discord or Telegram alerts.
  2. A scheduled report or check. The Schedule Trigger works like cron. Fetch numbers with the HTTP Request node, which can query any service with a REST API, and send a summary with the Send Email, Slack or Discord node.
  3. A webhook intake. The Webhook node gives a workflow its own URL, so a form, a payment provider or a Git host can start it, even when n8n has no trigger node for that service.
  4. Glue between two tools. Copy new rows, orders or tickets between systems. For a service without a node, the HTTP Request node calls its API and can import a curl command from its docs.

n8n's template library has starting points for most of these. Keep runs small: memory use grows with the amount of data, the number of nodes and the Code node, and n8n's memory guide suggests processing 200 rows per execution instead of 10,000. Build with test data, then publish: publishing makes production webhook URLs and schedules live, and production runs use the published version, not your latest edits.

Run n8n With Docker Compose on a Pinned Version

You need Docker Engine with Compose v2 (Ubuntu, Debian). n8n's Compose guide asks for at least 4 GB of RAM and 2 vCPUs for its full stack, which adds a Docker-in-Docker sandbox for n8n Assistant that this setup leaves out; see our requirements guide for sizing. On a Space-Node VPS for n8n and AI agents you get KVM with full root access in an EU data center; pick Ubuntu 24.04 LTS, the image the order form recommends.

Create ~/n8n with a .env file, which Compose reads to fill in the ${...} values (interpolation):

N8N_VERSION=2.45.7
POSTGRES_USER=n8n
POSTGRES_PASSWORD=change-me
POSTGRES_DB=n8n
ENCRYPTION_KEY=change-me
RUNNERS_AUTH_TOKEN=change-me

Replace each change-me with its own random string, for example from openssl rand -hex 32 (openssl-rand), keep the file out of version control and store the encryption key in your password manager. Next to it goes compose.yml, built from n8n's withPostgres example:

x-n8n: &n8n
  image: docker.n8n.io/n8nio/n8n:${N8N_VERSION}
  restart: always
  environment:
    - DB_TYPE=postgresdb
    - DB_POSTGRESDB_HOST=postgres
    - DB_POSTGRESDB_PORT=5432
    - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
    - DB_POSTGRESDB_USER=${POSTGRES_USER}
    - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
    - N8N_ENCRYPTION_KEY=${ENCRYPTION_KEY}
    - N8N_WEBHOOK_URL=https://n8n.example.com/
    - N8N_PROXY_HOPS=1
    - GENERIC_TIMEZONE=Europe/Amsterdam
    - TZ=Europe/Amsterdam
    - N8N_RUNNERS_MODE=external
    - N8N_RUNNERS_AUTH_TOKEN=${RUNNERS_AUTH_TOKEN}
    - N8N_RUNNERS_BROKER_LISTEN_ADDRESS=0.0.0.0
  volumes:
    - n8n_storage:/home/node/.n8n
  depends_on:
    postgres:
      condition: service_healthy

services:
  postgres:
    image: postgres:18
    restart: always
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
      - PGDATA=/var/lib/postgresql/data
    volumes:
      - db_storage:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
      interval: 5s
      timeout: 5s
      retries: 10

  n8n:
    <<: *n8n
    ports:
      - "127.0.0.1:5678:5678"

  n8n-runner:
    image: n8nio/runners:${N8N_VERSION}
    restart: always
    environment:
      - N8N_RUNNERS_AUTH_TOKEN=${RUNNERS_AUTH_TOKEN}
      - N8N_RUNNERS_TASK_BROKER_URI=http://n8n:5679
    depends_on:
      - n8n

volumes:
  db_storage:
  n8n_storage:

Use your own domain and time zone. Compose ignores top-level x- fields, and <<: *n8n copies that block into a service (fragments), so a queue mode worker can reuse it. Why the file looks like this:

  • Pinned version. n8n releases a new minor version most weeks and calls stable the production version. On 31 October 2026, Docker Hub showed latest, stable and 2.45.7 as one image; n8n 3.0 (27 October) was an early access release with breaking changes, a pre-release on GitHub. With a pinned number, a pull never changes your version, and the runner image, which must match n8n's version, reads the same variable.
  • Port on 127.0.0.1. Only the host itself can then reach port 5678 (port publishing), so all traffic goes through your reverse proxy.
  • Postgres. n8n's guide calls SQLite "fine for trying things out" and asks for Postgres in production with more than a handful of users or with workflows running around the clock. Keep PGDATA: Postgres 18 moved its default data folder, and without the line your database starts empty. To move from SQLite, see our SQLite vs PostgreSQL guide.
  • Runner container. Task runners are, in n8n's words, "the only isolation layer between user-provided code and n8n". Internal mode, the fallback when N8N_RUNNERS_MODE isn't set, isn't recommended for production and is deprecated from 3.0.
  • Own encryption key. Otherwise n8n generates one inside the volume. Queue mode workers need the same key.

Start it and check that n8n reached its database:

cd ~/n8n
sudo docker compose up -d
sudo docker compose ps
curl -s http://127.0.0.1:5678/healthz/readiness

The last line prints {"status":"ok"} once n8n has connected to Postgres and migrated (monitoring endpoints); before that, {"status":"error"} or no connection. Create the owner account through an SSH tunnel before a proxy forwards traffic; our security guide explains why and covers 2FA and further hardening.

To update, back up, change N8N_VERSION and run sudo docker compose pull and sudo docker compose up -d, which recreates changed containers and keeps volumes (compose up). n8n suggests updating at least once a month after checking the release notes; our update and rollback guide has the full routine.

Put Webhooks Behind a Reverse Proxy

n8n builds webhook URLs from N8N_PROTOCOL, N8N_HOST and N8N_PORT, which is wrong behind a proxy that serves port 443. Its reverse proxy page asks for N8N_WEBHOOK_URL set to your public URL, N8N_PROXY_HOPS=1 (both in the compose file) and a proxy that sends X-Forwarded-For, X-Forwarded-Host and X-Forwarded-Proto. N8N_WEBHOOK_URL exists from n8n 2.30.0 (queue mode docs); the older WEBHOOK_URL has been deprecated since 2.35.0 and still works, with a warning at startup (endpoint variables).

With Caddy, install its Debian and Ubuntu package, point your domain's A record at the VPS, open ports 80 and 443, and put this in /etc/caddy/Caddyfile:

n8n.example.com {
    reverse_proxy 127.0.0.1:5678
}

Run sudo systemctl reload caddy (running Caddy). Caddy gets and renews the certificate, redirects HTTP to HTTPS (automatic HTTPS) and sets all three headers (reverse_proxy). For Nginx and curl tests, see our webhook reverse proxy guide.

Each Webhook node has two URLs (workflow development). The test URL works after you select Listen for test event, stays registered for 120 seconds and shows the incoming data in the editor. The production URL works once the workflow is published, and its runs appear under Executions. Before you share a production URL, set the node's authentication (Basic, Header or JWT auth) or an IP allowlist.

Credentials and the Encryption Key

n8n tests a credential when you save it and encrypts it with the instance's key before it goes into the database. Three habits keep that safe:

  • Secrets go in credentials, not node fields. Workflows are saved as JSON, and an HTTP Request node imported from curl may carry authentication headers into every export. Use the node's Predefined Credential Type where one exists, as n8n recommends.
  • Limit where a credential goes. Set its Allowed HTTP Request Domains field to the API's domain, and no HTTP Request node can send it anywhere else.
  • The key is part of your data. A database restored without it gives Credentials could not be decrypted. The likely reason is that a different "encryptionKey" was used to encrypt the data. (n8n source). n8n also writes the key to the config file in its volume on first start; if that file and N8N_ENCRYPTION_KEY later disagree, n8n stops with Mismatching encryption keys (instance settings).

On the free Community edition, only the instance owner and a credential's creator can access it; sharing needs a paid plan (editions).

Queue Mode Only When One Process Isn't Enough

In the default regular mode, one process serves the editor, takes webhooks, fires schedules and runs every execution. Two cheaper steps come first:

  1. Cap parallel runs. Regular mode doesn't limit concurrent production executions, and too many "thrash the event loop" (concurrency control). Add - N8N_CONCURRENCY_PRODUCTION_LIMIT=20 (n8n's example value) to the x-n8n environment; runs over the limit wait and start in order of arrival.
  2. Keep runs small and leave pruning on: by default n8n deletes execution data after 336 hours or beyond 10,000 executions (execution variables).

Queue mode then splits the work: the main instance takes webhooks and timers and hands each execution through Redis to a worker. n8n doesn't recommend it with SQLite, every worker needs the main instance's encryption key, and binary data goes to the database, the queue mode default since n8n 2.0; filesystem storage isn't supported there. Webhook runs can pick up some extra latency. The free Community edition includes queue mode; multi-main needs Enterprise.

Following n8n's withPostgresAndWorker example, extend x-n8n:

x-n8n: &n8n
  # image, restart and volumes stay as they are
  environment:
    # keep the existing lines and add these four
    - EXECUTIONS_MODE=queue
    - QUEUE_BULL_REDIS_HOST=redis
    - QUEUE_HEALTH_CHECK_ACTIVE=true
    - OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS=true
  depends_on:
    postgres:
      condition: service_healthy
    redis:
      condition: service_healthy

Add redis_storage: under volumes: and these services:

  redis:
    image: redis:7-alpine
    restart: always
    volumes:
      - redis_storage:/data
    healthcheck:
      test: ['CMD', 'redis-cli', 'ping']
      interval: 5s
      timeout: 5s
      retries: 10

  n8n-worker:
    <<: *n8n
    command: worker
    depends_on:
      - n8n

  n8n-worker-runner:
    image: n8nio/runners:${N8N_VERSION}
    restart: always
    environment:
      - N8N_RUNNERS_AUTH_TOKEN=${RUNNERS_AUTH_TOKEN}
      - N8N_RUNNERS_TASK_BROKER_URI=http://n8n-worker:5679
    depends_on:
      - n8n-worker

Run sudo docker compose up -d. Through the fragment, the worker gets the same version, database and key. It runs 10 executions at once by default, or your N8N_CONCURRENCY_PRODUCTION_LIMIT if set. QUEUE_HEALTH_CHECK_ACTIVE turns on its /healthz endpoints, and the last line sends manual runs to workers too (queue mode variables), as n8n 3.0 always does. On one VPS the worker shares the same CPU and memory, so the gain is an editor process that no longer runs executions; workers on another server that reach the same Redis and database add capacity. Each worker needs its own runner, and workers sharing one volume need separate event log paths (event log files).

Back Up What a Restore Needs

n8n's backup page lists two parts: the .n8n folder, here the n8n_storage volume, whose config file holds the encryption key, and your Postgres database. pg_dump makes a consistent export while n8n keeps running:

cd ~/n8n
set -a && . ./.env && set +a
sudo docker compose exec -T postgres pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" > "n8n-$(date +%F).sql"

The second line loads .env into your shell, as the README of n8n's Postgres example does, and -T turns off the TTY that docker compose exec allocates by default (exec reference). Keep the dump with .env and compose.yml on another machine. Backups aren't included in the price of a Space-Node VPS (support can arrange them through a ticket), so keep your own copy either way. Our backup and restore guide adds the volume copy and a test restore on a new VPS. Never run docker compose down -v here, because n8n's README warns that it also deletes the volume with your key, and take a full backup before every update, as n8n recommends.

FAQ

Is self-hosted n8n free? The Community edition is: it's what n8n runs without a licence key. Its Sustainable Use License allows use "only for your own internal business purposes or for non-commercial or personal use". Our cost example compares n8n Cloud with a VPS over 12 months.

Should I use latest, stable or a version number? A version number, because latest and stable move with every release. Before a major jump such as 3.0, read the breaking changes and check Settings > Migration Report, which lists what on your instance needs attention.

Why does my Schedule Trigger run at the wrong time? Usually the time zone: without a workflow time zone, n8n uses the instance's, America/New_York unless you set GENERIC_TIMEZONE (time zone variables). Since n8n 2.45.0, "every N seconds" and "every N minutes" schedules count from publication, not clock boundaries; a cron expression keeps clock times. A run due during a restart still fires if n8n is back within the grace period (one minute by default); otherwise the node's If Execution Is Missed option decides, and its default skips the run (durable scheduler).

Why does my webhook answer 404? The requested webhook "..." is not registered. means nothing listens there: a test URL called without Listen for test event, or the production URL of an unpublished workflow. A wrong method gets This webhook is not registered for GET requests. Did you mean to make a POST request? (n8n source).

Can the Code node run Python? Yes, with task runners in external mode as set up above: since n8n 2.0 that's the only way to run Python Code nodes, and the n8nio/runners image holds both the JavaScript and the Python runner.

Sources

All opened on 31 October 2026: