Use the included Caddy container if
TCP ports 80 and 443 are available and DNS points your subdomain at this VPS.
Practical VPS tutorial
Install n8n on an Ubuntu VPS with Docker Compose, PostgreSQL and HTTPS. Follow the setup, test a webhook and fix common reverse-proxy and runner errors.
TCP ports 80 and 443 are available and DNS points your subdomain at this VPS.
another HTTPS site already owns those ports and can proxy to http://127.0.0.1:5678.
Docker Compose gives n8n a home on your VPS, with a permanent HTTPS address for webhooks. The important part is keeping workflows and credentials intact after a restart.

I'd start with one server, PostgreSQL and a reverse proxy. That's the setup below. By the end, you'll have the editor running on your domain and a small workflow that confirms both webhooks and Code nodes work.
I'd budget 2 vCPU, 4 GB RAM and 40 GB SSD for this small stack, then measure actual usage. Large files, browser automation and concurrent workflows can need much more memory.
Have these ready:
sudo docker compose version.n8n.example.com, with DNS pointing to the VPS.curl and openssl installed on the host.Already using Nginx or a hosting panel? Use the existing-proxy option in step 3.
The example pins n8n 2.45.7, listed as stable on October 31, 2026. Check the official releases when installing later; pinning a version makes updates easier to track.

Keep the deployment in /opt/n8n so the configuration is easy to find later:
sudo mkdir -p /opt/n8n
sudo chown "$(id -u):$(id -g)" /opt/n8n
cd /opt/n8nCreate .env with separate secrets for credentials, runners and PostgreSQL. This block refuses to overwrite an existing file:
(
umask 077
set -o noclobber
cat > .env <<EOF
N8N_VERSION=2.45.7
N8N_HOST=n8n.example.com
GENERIC_TIMEZONE=UTC
N8N_ENCRYPTION_KEY=$(openssl rand -hex 32)
N8N_RUNNERS_AUTH_TOKEN=$(openssl rand -hex 32)
POSTGRES_PASSWORD=$(openssl rand -hex 32)
EOF
)Edit .env with your hostname and timezone, such as Europe/London or Asia/Shanghai. Keep this file out of Git.
Keep the encryption key. Existing credentials depend on it. Include it in backups and don't regenerate it during updates.
Here's what the four services do:
Save the following as /opt/n8n/compose.yml. The database and runner broker have no public port mapping; n8n's host port is bound to localhost.
name: n8n
services:
postgres:
image: postgres:18.6-alpine
restart: unless-stopped
environment:
POSTGRES_USER: n8n
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}
POSTGRES_DB: n8n
PGDATA: /var/lib/postgresql/18/docker
volumes:
- postgres_data:/var/lib/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U n8n -d n8n"]
interval: 10s
timeout: 5s
retries: 10
logging:
driver: local
n8n:
image: docker.n8n.io/n8nio/n8n:${N8N_VERSION:?set N8N_VERSION}
restart: unless-stopped
environment:
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: postgres
DB_POSTGRESDB_PORT: "5432"
DB_POSTGRESDB_DATABASE: n8n
DB_POSTGRESDB_USER: n8n
DB_POSTGRESDB_PASSWORD: ${POSTGRES_PASSWORD}
N8N_HOST: ${N8N_HOST:?set N8N_HOST}
N8N_PROTOCOL: https
N8N_PORT: "5678"
N8N_EDITOR_BASE_URL: https://${N8N_HOST}/
N8N_WEBHOOK_URL: https://${N8N_HOST}/
N8N_PROXY_HOPS: "1"
GENERIC_TIMEZONE: ${GENERIC_TIMEZONE}
TZ: ${GENERIC_TIMEZONE}
N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY:?set N8N_ENCRYPTION_KEY}
N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS: "true"
N8N_RUNNERS_MODE: external
N8N_RUNNERS_BROKER_LISTEN_ADDRESS: 0.0.0.0
N8N_RUNNERS_AUTH_TOKEN: ${N8N_RUNNERS_AUTH_TOKEN:?set N8N_RUNNERS_AUTH_TOKEN}
depends_on:
postgres:
condition: service_healthy
ports:
- "127.0.0.1:5678:5678"
volumes:
- n8n_data:/home/node/.n8n
logging:
driver: local
runners:
image: n8nio/runners:${N8N_VERSION}
restart: unless-stopped
environment:
N8N_RUNNERS_TASK_BROKER_URI: http://n8n:5679
N8N_RUNNERS_AUTH_TOKEN: ${N8N_RUNNERS_AUTH_TOKEN}
depends_on:
- n8n
user: "65532:65532"
read_only: true
tmpfs:
- /tmp:uid=65532,gid=65532,mode=1777
security_opt:
- no-new-privileges:true
logging:
driver: local
caddy:
image: caddy:2-alpine
restart: unless-stopped
environment:
N8N_HOST: ${N8N_HOST}
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
depends_on:
- n8n
logging:
driver: local
volumes:
postgres_data:
n8n_data:
caddy_data:
caddy_config:A few details matter here:
N8N_VERSION, following the external runner guidance./home/node/.n8n hold different parts of the instance.For a shared PostgreSQL server, use a dedicated application role and database instead of the server's administrator account.
For the included Caddy container, save this as /opt/n8n/Caddyfile:
{$N8N_HOST} {
reverse_proxy n8n:5678
}Caddy uses the hostname from .env and obtains a certificate automatically when DNS and connectivity are correct. It also handles WebSockets and forwarded headers. There's no need to expose port 5678 publicly.
Remove the caddy service from the Compose file and use your existing HTTPS site to proxy to http://127.0.0.1:5678. Preserve Host, X-Forwarded-Host, X-Forwarded-Proto and X-Forwarded-For, and disable proxy caching for n8n.
That localhost address assumes the proxy runs on the host. A proxy in another container needs a shared Docker network and the upstream n8n:5678 instead.
The Compose example sets N8N_PROXY_HOPS=1 for one reverse proxy. If you put a CDN or another proxy in front, review the real request chain and trusted headers. See n8n's reverse-proxy configuration.
From the project folder, validate the file before starting anything:
cd /opt/n8n
sudo docker compose config --quietIf validation succeeds, pull the images and launch the stack:
sudo docker compose pull
sudo docker compose up -d
sudo docker compose psOnce PostgreSQL has initialized, check n8n and the logs:
curl --fail http://127.0.0.1:5678/healthz
sudo docker compose logs --tail=50 n8n runnersOpen your HTTPS hostname and create the owner account. Restrict initial access with a VPN or proxy rule until it's ready, and confirm the certificate is valid before logging in.
Now check that a workflow actually runs.
Create a new workflow with two connected nodes:
GET, set its path to vps-check and leave the response mode as immediate for this test.return [{ json: { ok: true, message: 'n8n is running on the VPS' } }];Publish the workflow. Copy its Production URL, which should start with your HTTPS hostname and should not contain :5678. From your computer or another machine, call it:
curl --fail https://n8n.example.com/webhook/vps-checkAn immediate HTTP response confirms receipt, not successful execution. Open Executions and check that the Code node finished with ok: true. This tests the public route and runner together.
Test URLs work only while their listener is active. Always-on integrations need a published production URL, as the Webhook documentation explains.
address already in use for port 80 or 443Another web server owns the port. Use the existing-proxy option instead of running Caddy.502 Bad GatewayCheck n8n logs and the upstream address. A container's localhost is not the VPS host.N8N_WEBHOOK_URL, forwarded headers and proxy hops, then recreate the n8n container.Current n8n documentation uses N8N_WEBHOOK_URL; the older WEBHOOK_URL variable is deprecated. After changing .env, run sudo docker compose up -d so Compose applies changed environment values. Restarting the old container alone does not load a new environment.
Back up PostgreSQL, n8n_data, Compose files and .env. Workflow exports alone aren't a full backup. Follow the Docker backup guide for dumps, archives and a restore test.
For updates, back up first, read the release notes and change N8N_VERSION in .env. Then run:
sudo docker compose pull
sudo docker compose up -d
sudo docker compose logs --tail=50 n8n runnersRecheck the webhook and Code node afterward. A database migration can make rollback more involved than restoring the previous image tag. And keep docker compose down -v out of your normal update routine: it removes the data volumes.
For light testing, possibly. I'd budget 4 GB for this PostgreSQL and external-runner stack, then measure actual executions. Workflows processing large files or several concurrent jobs can need considerably more.
Not when the workflow calls an external model API. The remote provider runs the model. Local inference is a separate workload with its own CPU, RAM or GPU requirements.
n8n supports SQLite too. This guide chooses PostgreSQL for a separate database and a clear backup path. Existing SQLite data will not appear in PostgreSQL just because you change the connection settings.
Next step
Commands assume a fresh Ubuntu server. Replace domains, users, database names and provider-specific values before running them. VPS sizing is a practical starting point, not a guarantee: monitor the real workload and resize when CPU, memory, disk or network headroom becomes tight.
Affiliate links: you pay the same price as buying direct.