VPS for n8n: Docker Setup, Private Database and Recovery Planning
Plan n8n on a VPS with pinned Docker images, PostgreSQL roles, HTTPS webhooks, an external task runner and a protected backup plus restore-validation process.
The short answer
A reliable n8n VPS needs measured capacity, HTTPS with correct proxy/webhook settings, a private database and a recovery set containing the matching encryption key. This guide develops a single-instance Docker Compose reference with separate database roles, an external task runner, safe verification and an isolated restore drill. All deployment examples remain unexecuted.

Reading options
On this page
- Decide whether self-hosting fits your team
- Size the jobs, not the number of workflows
- Example: one n8n instance, PostgreSQL and Caddy
- Verify the public workflow path
- Back up enough to restore
- Prove recovery before relying on the backup
- Upgrade with a recovery point, not just an older image tag
- Scale after finding the bottleneck
- Reader questions
- Sources & further reading
Before you start
Authorized Linux administration, a separate evaluation host, Docker Engine/Compose v2, DNS and restricted first-run access, reviewed n8n 2.x/runner and PostgreSQL 17 images, private secrets and recovery ownership. Examples are unexecuted.
The easiest installation is not always the easiest system to recover. A workflow can look fine in the editor while its public webhook points to the wrong address, its execution history fills the disk, or its saved credentials depend on a key that was never backed up.
Use this guide to plan a single-instance n8n service with a private PostgreSQL database, an HTTPS entry point and a recovery process you can demonstrate. The configuration is an unexecuted reference, not a tested Hostlelo deployment or a promise of production capacity. Start on a separate evaluation host with mock data; promote the design only after the access, workflow and restore checks pass.
Decide whether self-hosting fits your team
The official n8n Docker Compose guide assumes server-administration skills. Someone must own updates, backups, access control and incident response. If nobody owns those tasks, compare a managed option rather than assuming a VPS is cheaper overall.
n8n's Sustainable Use License restricts permitted use. Do not assume that a self-hosted installation grants permission to sell hosted n8n access. Check the applicable license and commercial arrangement for your business model.
Size the jobs, not the number of workflows
Workload characteristic | What to measure | What may need attention |
|---|---|---|
Large spreadsheet or document processing | Peak memory per active execution | Memory use, file handling and concurrency |
Many scheduled jobs at the same minute | Simultaneous executions and completion delay | Scheduling spread, CPU and downstream API limits |
File-heavy automations | Stored binary data and disk growth | Retention, permitted storage backend and backups |
Slow external APIs | Waiting time, retries and queue depth | Timeouts, retry policy and idempotent actions |
There is no tested RAM recommendation in this article. A useful pilot runs your actual workflow with representative data, including an expected busy period. Record peak usage before picking the production plan.
Count the whole stack: n8n, PostgreSQL, the reverse proxy, task runners, logs and backups. Measure a representative busy period, including the largest permitted payload and retries after an upstream failure. Record peak memory, available disk, completion time and failed executions. Set limits for payload size and simultaneous work before buying more capacity. More vCPUs do not solve a remote API quota or a workflow that loads unnecessarily large files into memory.
The same VPS is one failure domain even when every component is in a separate container. Decide how much work you can afford to lose and how long an outage can last. Those recovery objectives determine backup frequency, off-host storage and whether one host remains a sensible design. A nightly copy is not automatically sufficient for hourly business-critical work.
Example: one n8n instance, PostgreSQL and Caddy

This template targets a reviewed n8n 2.x release with N8N_WEBHOOK_URL support, a matching external task-runner image, a supported PostgreSQL 17 image, Caddy 2, and Docker Engine with Compose v2 on Linux. Resolve every image placeholder to an exact reviewed version or digest. Check release notes and security updates at deployment time; neither a floating latest tag nor an old pin is an update strategy. The PostgreSQL support policy lists 17 as supported at this review.
The illustration shows the main request and recovery paths; the template also includes an external Code-node runner. It deliberately omits n8n Assistant, its sandbox infrastructure, queue workers and high availability. The newer official Compose guide includes additional Assistant components; do not copy privileged development sandbox services into a production VPS without a separate design review.
Use a new hostname such as n8n.example.com, point its DNS to the VPS and allow inbound HTTPS plus the HTTP access needed for your chosen certificate validation. Review IPv6 records too. Keep SSH restricted through your normal access policy.
Create a private .env file containing these keys, replace every placeholder, and keep it out of source control and shared support bundles. Generate independent high-entropy secrets with your approved password manager or secret-management process. No example value below is a usable password.
N8N_IMAGE=docker.n8n.io/n8nio/n8n:REPLACE_WITH_REVIEWED_2_X_VERSION
RUNNERS_IMAGE=n8nio/runners:REPLACE_WITH_MATCHING_N8N_VERSION
POSTGRES_IMAGE=postgres:REPLACE_WITH_REVIEWED_17_X_VERSION
CADDY_IMAGE=caddy:REPLACE_WITH_REVIEWED_2_X_VERSION
N8N_DOMAIN=n8n.example.com
ADMIN_DB_PASSWORD=REPLACE_WITH_A_UNIQUE_RANDOM_SECRET
APP_DB_PASSWORD=REPLACE_WITH_A_DIFFERENT_RANDOM_SECRET
N8N_ENCRYPTION_KEY=REPLACE_WITH_A_SEPARATE_RANDOM_SECRET
RUNNERS_AUTH_TOKEN=REPLACE_WITH_ANOTHER_RANDOM_SECRET
GENERIC_TIMEZONE=Etc/UTC
TZ=Etc/UTCUse separate secrets and preserve the encryption key through upgrades and restores. n8n encrypts stored credentials; a restored database without its matching key is not a complete credential recovery.
A private .env file is a simple evaluation mechanism, not a secret vault: Docker administrators and resolved configuration can expose environment values. For production, use the documented file-based n8n configuration and a reviewed secret-delivery mechanism where supported. Compose secrets mount files into selected services; the source files and backup copies still need protection. Do not assume every sidecar supports the same _FILE variables.
Save this as compose.yaml:
services:
postgres:
image: ${POSTGRES_IMAGE:?Set POSTGRES_IMAGE}
restart: unless-stopped
environment:
POSTGRES_DB: n8n
POSTGRES_USER: n8n_admin
POSTGRES_PASSWORD: ${ADMIN_DB_PASSWORD:?Set ADMIN_DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U n8n_admin -d n8n"]
interval: 10s
timeout: 5s
retries: 10
n8n:
image: ${N8N_IMAGE:?Set N8N_IMAGE}
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
environment:
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: postgres
DB_POSTGRESDB_PORT: "5432"
DB_POSTGRESDB_DATABASE: n8n
DB_POSTGRESDB_SCHEMA: n8n
DB_POSTGRESDB_USER: n8n_app
DB_POSTGRESDB_PASSWORD: ${APP_DB_PASSWORD:?Set APP_DB_PASSWORD}
N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY:?Set N8N_ENCRYPTION_KEY}
N8N_HOST: ${N8N_DOMAIN:?Set N8N_DOMAIN}
N8N_PORT: "5678"
N8N_PROTOCOL: https
N8N_EDITOR_BASE_URL: https://${N8N_DOMAIN}/
N8N_WEBHOOK_URL: https://${N8N_DOMAIN}/
N8N_PROXY_HOPS: "1"
N8N_BLOCK_ENV_ACCESS_IN_NODE: "true"
N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS: "true"
N8N_RUNNERS_MODE: external
N8N_RUNNERS_BROKER_LISTEN_ADDRESS: 0.0.0.0
N8N_RUNNERS_AUTH_TOKEN: ${RUNNERS_AUTH_TOKEN:?Set RUNNERS_AUTH_TOKEN}
GENERIC_TIMEZONE: ${GENERIC_TIMEZONE:?Set GENERIC_TIMEZONE}
TZ: ${TZ:?Set TZ}
volumes:
- n8n_data:/home/node/.n8n
task-runners:
image: ${RUNNERS_IMAGE:?Set RUNNERS_IMAGE}
restart: unless-stopped
depends_on:
- n8n
environment:
N8N_RUNNERS_TASK_BROKER_URI: http://n8n:5679
N8N_RUNNERS_AUTH_TOKEN: ${RUNNERS_AUTH_TOKEN:?Set RUNNERS_AUTH_TOKEN}
caddy:
image: ${CADDY_IMAGE:?Set CADDY_IMAGE}
restart: unless-stopped
environment:
N8N_DOMAIN: ${N8N_DOMAIN:?Set N8N_DOMAIN}
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
volumes:
postgres_data:
n8n_data:
caddy_data:
caddy_config:The PostgreSQL volume target above is intentionally for the selected 17.x layout. The official image documentation changes the default layout from 18; switching a major-version tag is not a database migration. Its POSTGRES_USER creates a bootstrap superuser, so n8n uses a separate n8n_app role created below. Initialization variables apply to an empty data directory, not an existing database. Never delete a volume to make changed credentials “take effect.”
The database variable reference documents the PostgreSQL connection and schema settings. The runner connects over a private Compose service address; port 5679 is not published. Keep its image version aligned with n8n and follow external-runner setup. Before production, apply and test the runner-hardening guidance, including restricted privileges and writable paths. Do not mount the Docker socket or host secrets into it.
Save a Caddyfile beside it:
{$N8N_DOMAIN} {
reverse_proxy n8n:5678
}Only Caddy publishes host ports. PostgreSQL and n8n communicate on the Compose network. Read Caddy's reverse-proxy documentation and the n8n proxy settings when adapting this topology. N8N_PROXY_HOPS=1 assumes exactly this one-proxy path; adding a CDN changes the trust design.
Caddy normally sets the forwarded client, host and scheme headers; its proxy reference explains the trust boundary. Here TLS terminates at Caddy and the private upstream is HTTP on 5678. N8N_EDITOR_BASE_URL identifies the public editor address. If a CDN or load balancer is added, review trusted proxy addresses and hop counts together rather than blindly increasing a number.
Before starting the editor, arrange an access policy that permits your administrator but prevents strangers reaching first-run account setup. Preserve the certificate-validation traffic required by Caddy automatic HTTPS. After owner setup, review editor access separately from public webhook access; a blanket login wall in front of every path can break legitimate webhook senders.
For a new, empty evaluation deployment only, validate the files and start PostgreSQL first. These commands create containers and persistent volumes; they are not read-only checks. config --quiet validates configuration syntax without printing the resolved secret values. The image pull consumes network transfer and disk space.
chmod 600 .env
docker compose config --quiet
docker compose pull
docker compose up -d postgres
docker compose psOnce PostgreSQL is healthy, open a private administrative session on this new database. Have the application password ready through your secure secret process; do not put it in SQL text, shell history or a ticket. The PostgreSQL role documentation explains why the application must not inherit superuser privileges.
docker compose exec postgres psql --username=n8n_admin --dbname=n8nInside psql, create a login role without cluster-administration rights and a dedicated schema it owns. At the \password prompts, enter the same secret configured as APP_DB_PASSWORD; the value is deliberately absent here. This is for the fresh database only, not a migration script to run repeatedly on an existing installation.
CREATE ROLE n8n_app LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE;
\password n8n_app
GRANT CONNECT ON DATABASE n8n TO n8n_app;
CREATE SCHEMA n8n AUTHORIZATION n8n_app;
\qThe schema ownership allows n8n to create and migrate its own tables without owning the PostgreSQL cluster. Confirm the role can connect with its password and that the schema is present before starting n8n. A healthy PostgreSQL container alone does not prove the application login is valid. Then, with the first-run access restriction already in place:
docker compose up -d n8n task-runners caddy
docker compose ps
docker compose logs --tail=100 n8n task-runnersAvoid printing resolved configuration or posting logs publicly: they can contain secrets or workflow data. Complete owner-account setup through the restricted HTTPS address, verify login/logout and establish the intended editor permissions before opening any required public paths. Do not disable secure cookies or authentication to hide a proxy error. A restart policy helps restart a process; it does not prove the service is healthy.
Verify the public workflow path
Create a harmless test workflow that receives a unique identifier and records or returns it. Use its production webhook URL with the workflow published or active as required by the chosen release. Do not confuse the editor's temporary test URL with the production endpoint.
Check HTTPS, the displayed webhook hostname and an external request. Confirm one intended execution. Then retry deliberately and check that the workflow cannot duplicate a consequential business action. Do not test using a real payment or a destructive production operation.
The current proxy documentation states that N8N_WEBHOOK_URL replaces WEBHOOK_URL, deprecated from n8n 2.35.0. This template follows that newer setting. Older installations need a version-specific migration review, not a mixture of variable names copied from different tutorials.
Check | Pass condition | If it fails |
|---|---|---|
External HTTPS request | Correct hostname and valid certificate; expected redirect behavior | Check A/AAAA records, validation reachability and proxy logs |
Private backend ports | No public service on 5432, 5678 or 5679 | Review container publishing and upstream routing before proceeding |
Production webhook | One expected execution from an authorized external request | Check URL, workflow publication, webhook authentication and proxy path |
Runner and scheduled job | Safe Code-node test completes; schedule uses the intended timezone | Check matching runner version, token, broker connection and timezone |
Retried event | Repeated event ID does not repeat an irreversible action | Add deduplication/idempotency before using real integrations |
Back up enough to restore
Back up PostgreSQL with a database-consistent method, preserve n8n's persistent data and retain the matching encryption key through a protected secret-backup process. Include configuration, required file data and pinned version information. Store a recovery copy separately from the VPS.
Recovery component | What the recovery set must include | Why it matters |
|---|---|---|
PostgreSQL | Consistent database backup plus a documented way to recreate roles and ownership | Workflows, credentials and execution state are not just files in the editor |
Encryption material | The exact key matching the backed-up credentials, protected separately | A new random key cannot decrypt the old credential values |
Persistent and binary data | The .n8n volume and every configured file/object-storage location | Database rows alone may refer to missing files |
Configuration and TLS state | Compose/Caddy files, secret references, Caddy persistent volumes, timezone and exact image identities | Recovery must reproduce configuration and protect certificate private keys |
Operational record | Backup timestamp, job result, integrity check, retention and restore-test result | A file existing does not prove it can restore the service |
For a small single-instance recovery plan, a PostgreSQL logical dump may be appropriate. pg_dump produces a consistent single-database export, but it does not include cluster roles or external file storage and is not a universal production-backup solution. If your recovery objective requires point-in-time recovery or a shorter data-loss window, use a suitable PostgreSQL backup/WAL strategy rather than merely increasing dump frequency.
Coordinate the database and file-data recovery point. For a straightforward maintenance-window backup, pause incoming work, let active executions settle, and stop n8n and its runners before capturing the application files and a database-consistent backup. Keep PostgreSQL running if the selected method requires it. Do not copy a live database volume as though it were an ordinary directory; use a documented PostgreSQL-aware method.
Treat every backup as sensitive: workflow payloads may contain personal or business data even when stored credentials are encrypted. Encrypt recovery copies, restrict access, store at least one copy outside the VPS failure domain, and keep the decryption material recoverable through a separate protected process. Set retention and deletion deliberately. Alert on a missed or failed backup, not just on a full disk.
A workflow export is useful, but it is not a complete database, credential and execution-state backup. Test recovery in an isolated environment with outbound workflows disabled before reconnecting production credentials.
Prove recovery before relying on the backup
Restore into a separate environment with production DNS untouched, inbound triggers blocked and outbound access denied before n8n starts. Network isolation matters because a restored workflow may retain active schedules or credentials. Use only trusted backup files. Recreate the required database role/schema ownership, restore the database and file data, and supply the matching encryption key and recorded image versions.
Before allowing normal connectivity, inspect workflow publication and schedules, replace integration credentials with test credentials, and prevent duplicate production processing. Then verify owner login, expected workflow inventory, representative file retrieval and a harmless workflow using a test credential. Exercise a private test webhook and a scheduled job; restarting the container successfully is not enough.
Record the backup timestamp, the recovered data point, elapsed restore time and any manual fixes. Compare them with your agreed recovery objectives. Keep production isolated if credentials fail to decrypt, files are missing, database ownership is wrong or a workflow would fire a real external action. Repair the recovery procedure and repeat the drill before declaring the backup usable.
Upgrade with a recovery point, not just an older image tag
Read the n8n and PostgreSQL release notes, stage the intended change on a restored copy, and repeat the webhook, runner and credential checks. Take a fresh coordinated backup before the production change. Keep the previous image identities and configuration, but do not assume running an older n8n image against a newly migrated database is safe. Follow release-specific rollback guidance or restore the compatible pre-upgrade recovery set during an approved maintenance window.
If recovery uses an older database snapshot, reconcile events that arrived after that snapshot before replaying them. A technically successful restore can still duplicate an invoice, message or order when upstream senders retry. The recovery owner needs a replay/deduplication decision, not only a green container status.
Review execution-data retention. Decide what evidence you need to troubleshoot and how long sensitive payloads should remain. Do not keep everything indefinitely by accident.
Scale after finding the bottleneck
Queue mode adds Redis and workers sharing database access and the correct encryption key. Follow its current database, binary-data and feature requirements. A larger worker pool cannot fix a downstream API quota.
Before ordering a Cloud VPS, describe your workflow sizes and operating responsibilities. For the broader design, read hosting AI-agent applications.
Reader questions
How much RAM does n8n need on a VPS?
It depends on workflow data, concurrent executions and the surrounding services. Measure a pilot including the database and proxy; workflow count is not a reliable memory estimate.
Does Docker automatically back up n8n?
No. Volumes persist data across container replacement, but you still need a consistent backup, protected keys and a tested restore procedure.
Why does the editor work but my webhook fail?
Check the public URL setting, proxy path, DNS, TLS and whether you are using an enabled production webhook. An accessible editor does not prove the external trigger path works.
Was this guide helpful?
Help us make the next update better.
Sources & further reading
- n8n Docker Compose deployment
- n8n database variables
- n8n encryption-key configuration
- n8n reverse-proxy settings
- n8n execution-data retention
- n8n queue mode
- n8n license
- Caddy reverse proxy
- Official PostgreSQL image and data layout
- Current n8n Compose guide and Assistant scope
- n8n external task runners
- n8n task-runner hardening
- n8n file-based configuration
- n8n deployment variables
- n8n security variables
- Docker Compose secrets
- Caddy forwarded headers
- Caddy automatic HTTPS
- PostgreSQL version support
- PostgreSQL role creation
- PostgreSQL schema ownership
- PostgreSQL psql password prompt
- PostgreSQL pg_dump scope and restore cautions
- PostgreSQL backup and restore
Originally published . About our editorial updates.



