Self-hosted n8n on a VPS: glowing workflow nodes above a server where only an HTTPS gateway opens to the internet

How to Self-Host n8n on a VPS With Docker Compose, PostgreSQL, and HTTPS

Table of Contents

You can self-host n8n on a VPS, and a production-ready setup is Docker Compose, a PostgreSQL database, and HTTPS (the padlock connection) on a right-sized server. Self-hosting n8n, a workflow automation tool that connects apps and APIs, means running it on a server you control instead of on n8n Cloud, its hosted service. A VPS, or virtual private server, is your own slice of a physical server with root (full administrator) access, which is what VPS hosting gives you.

This n8n VPS hosting guide ends with a secured instance, tested backups, and updates you can roll back. Docker runs each program in its own container, a sealed package with everything it needs, and Docker Compose starts several containers from one file. The guide is for people on execution-priced n8n Cloud plans, agencies, and teams that want their data on their own server.

What you’ll need

  • An unmanaged VPS (a plain server with no control panel, which you run yourself) with root access, sized as explained below
  • Ubuntu 26.04 LTS (the version this guide was tested on; N6 Cloud also offers 22.04 and 24.04)
  • SSH key access from your computer (a key file that logs you in to the server without a password)
  • A domain name, such as example.com, whose DNS settings you can change
  • About 30 minutes of hands-on time, plus DNS waiting

How this guide was tested. N6 Cloud ran every command here on a fresh 1 vCPU, 1 GB server running Ubuntu 26.04 LTS in a Western Canada data centre, then resized it in place to 2 GB and 4 GB with two vCPUs each. The stack was n8n 2.49.6, PostgreSQL 18.7, Caddy 2.11.9 (the web server that handles HTTPS), and Docker Engine 29.10.1. Outside checks came from a separate computer.

Three places to run n8n side by side: n8n Cloud, your own always-on VPS in the spotlight, and a laptop whose workflows stop

What Self-Hosting n8n on a VPS Means

Running n8n on your own VPS gives you n8n’s free Community edition, the version that needs no paid licence, on an always-on server you control. The n8n pricing page and edition comparison state no execution quota for it: quotas belong to n8n Cloud plans and paid licences, so on your own server, memory is the limit. In return, you take over the upkeep that n8n Cloud does for you. Table 1 compares three common places to run n8n.

n8n Cloud A VPS you run Your own laptop
Who maintains it
n8n
You (the provider looks after the hardware and network)
You
Keeps running when your computer is off
Yes
Yes
No
Other apps can reach it from the internet
Yes
Yes, at your own domain
Not without extra setup
How you pay
A monthly plan priced by the number of executions (one execution is one run of a workflow)
A fixed bill for the server; the Community edition is free
Nothing extra
Best suited to
Teams that don’t want to run a server
Always-on workflows and data you control
Learning n8n and testing workflows

A laptop is fine for learning n8n, but scheduled workflows stop when the lid closes. The n8n documentation is plain about the trade-off: “n8n recommends self-hosting for expert users. Mistakes can lead to data loss, security issues, and downtime.” The guide to managed vs unmanaged VPS hosting shows which server tasks a provider takes on.

The Community edition “includes almost the complete feature set”, n8n says, and the gaps are mostly team features. It has no single sign-on (SSO: logging in with a company account through SAML, OIDC, or LDAP) and no Git version control. Environments, external secrets, team projects, custom variables, and log streaming are also missing. Small teams miss sharing first: each colleague can have a login, but only the owner and a workflow’s creator can open that workflow. The current list is on n8n’s Community edition features page.

A free registered key, emailed when you sign up during the owner setup, adds folders, debug in editor, and custom execution data. Paid licences add the team features, and n8n calls its pricing page “the source of truth” for each plan. If you build workflows for clients, n8n’s licence FAQ is where n8n explains what its Sustainable Use License allows for that work, so read it before you commit.

Checking n8n VPS requirements: a domain's A record pointing at a Linux server, with memory as the part that decides its size

n8n VPS Requirements Before You Order a Server

Running n8n needs a Linux VPS, a domain you control, and enough memory for the heaviest work n8n does at once. The address comes first, because other apps rely on a permanent HTTPS address. Size comes second, and it depends on your heaviest job, not how many workflows you have.

Operating System, Domain, and DNS Record

Your n8n instance needs a Linux operating system and a subdomain that points at the server. This guide uses Ubuntu 26.04 LTS, where LTS (long-term support) means years of security updates. Debian 12 or 13 also runs Docker, though Docker’s own installation steps for it differ slightly.

A domain is your web address, such as example.com, and DNS (the Domain Name System) turns names into server addresses. An A record, added where you manage your domain, maps a name such as n8n.example.com to the server’s IPv4 address, such as 203.0.113.10. An AAAA record does the same for IPv6, and you need one only if your server has an IPv6 address. A subdomain gives n8n its own address, separate from your website.

A reverse proxy sits in front of n8n, receives every request, and passes it on; this guide uses Caddy. HTTPS encrypts the connection with a certificate Caddy gets and renews, and n8n needs it because its login cookie is secure by default. Over plain HTTP, n8n shows this warning instead of the login form: “Your n8n server is configured to use a secure cookie, however you are either visiting this via an insecure URL, or using Safari.”

How Much CPU, RAM, and Disk Does n8n Need?

Memory, not CPU, decides the server size, and N6 Cloud’s measurements point to 2 GB as the practical minimum. Each execution’s data stays in memory while it runs, so load grows with how many executions run at once and how much data each carries. Code nodes (which run in a separate process called the task runner) and binary files such as PDFs add to it. Every call to a webhook (an address other apps call to start a workflow) starts its own execution.

n8n’s documentation says the software alone uses around 180 MiB of RAM (a MiB is about 1.05 megabytes), and n8n Cloud caps memory between 640 MiB and 4,096 MiB by plan. A self-hosted server also runs PostgreSQL, Caddy, and Docker, so N6 Cloud measured the whole stack. Table 2 shows the whole server’s memory in use, in MiB, by load and size.

Load 1 GB server (1 vCPU) 2 GB server (2 vCPU) 4 GB server (2 vCPU)
Idle, 4 workflows published
631, pass
806, pass
916, pass
10 webhook calls at a time for 60 seconds
694, pass
936, pass
1,053, pass
5 workflows polling every minute for 10 minutes
652, pass
833, pass
920, pass
Largest Code-node dataset that passed (items of about 1 KB)
10,000 items (peak 747)
50,000 items (peak 1,156)
200,000 items (peak 2,187)
First dataset that failed
50,000 items: task runner disconnected
200,000 items: n8n killed for lack of memory
None up to 200,000
Download and save a 50 MB file
Peak 726, pass
Peak 911, pass
Peak 995, pass

The figures come from free -m on the test server: medians of three samples (five for the polling row), and peaks of single runs for the dataset and file rows. Loads were synthetic and ran on the server itself; the 1 GB size had one vCPU (virtual processor core), while the others had two. Figure 1 splits the 2 GB results by container, up to the failed run.

Self-hosted n8n memory by container on 2 GB: idle, 10 webhooks, a 50,000-item run that passed, and a 200,000-item run that failed
Figure 1. On 2 GB, the 50,000-item run still left 41% of memory free, while the 200,000-item run left 97 MiB and n8n was killed.

The margins suggest a rule: choose the smallest size where your heaviest job passes with about a third of memory free. That rule is where the 2 GB minimum comes from, and it makes 4 GB the choice for executions with hundreds of thousands of items or for the workers in the scaling section. A 1 GB server isn’t recommended: restarts took minutes, webhooks ran at 4.8 calls per second against 12.7 on 2 GB, and n8n’s command-line tools ran out of memory.

Disk is rarely the limit: the four images (the packages Docker downloads and runs as containers) took 3.87 GB unpacked, so memory is the number to watch. Once your workflows are running, check each container’s share with the command N6 Cloud measured with. Compare its snapshot with Table 2:

				
					sudo docker stats --no-stream
				
			

The MEM USAGE / LIMIT column shows each container’s memory against the server’s total. Near the limit, the task runner disconnects or n8n restarts, and the scaling section covers both. For anything else you run on the same server, see how much RAM your VPS needs.

Setting up n8n with Docker Compose: a compose.yaml file and a sealed .env file with its encryption key, tested by a webhook

Step-by-Step n8n Setup With Docker Compose

The n8n Docker Compose setup takes five steps: prepare the server, write the Compose file, fill in the .env settings file, create the owner account privately, and test from another computer. This order keeps the editor off the public internet until it has an owner. Fix any output that doesn’t match before you move on.

Prepare the Server and Install Docker

Log in to the new server as root with your SSH key, then prepare it the same way as any Docker server, in this order:

  • Update the packages and reboot.
  • Create a sudo user named deploy, a normal account that can run administrator commands by typing sudo first, and log in as deploy.
  • Allow only ports 22 (SSH), 80, and 443 (web) through UFW, Ubuntu’s firewall. A port is a numbered door that a program listens on.
  • Turn off root and password logins over SSH, then confirm with sudo sshd -T.
  • Install Docker Engine and the Compose plugin from Docker’s own repository, the download source Ubuntu’s apt installer reads.
  • Switch Docker to the local log driver so container logs can’t fill the disk.

If you’re new to SSH, N6 Cloud’s server setup guide shows how to create SSH keys and make your first root login. Add the A record from the DNS section now too. The record will then point at the server by the time Caddy asks for a certificate.

The Docker VPS guide has the commands for every step in this order, and they’re the ones N6 Cloud’s test ran. Follow its SSH step to the end, where sudo sshd -T should show both permitrootlogin no and passwordauthentication no. Keep your first session open until a fresh login as your new user works, so a mistake can’t lock you out.

Write the compose.yaml for n8n, PostgreSQL, a Task Runner, and Caddy

A production n8n stack is four containers, and only Caddy faces the internet, while n8n, its runner, and PostgreSQL talk on a private Docker network. Create the folder with mkdir -p /home/deploy/n8n, move into it with cd /home/deploy/n8n, and open a new file with nano compose.yaml. Paste the file below, press Ctrl+O and Enter to save, and press Ctrl+X to close the editor. Every later command runs in that folder.

				
					services:
  caddy:
    image: caddy:2.11.9
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    depends_on:
      - n8n

  n8n:
    image: n8nio/n8n:2.49.6
    restart: unless-stopped
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      - N8N_HOST
      - N8N_PROTOCOL=https
      - N8N_PORT=5678
      - N8N_WEBHOOK_URL
      - N8N_PROXY_HOPS=1
      - GENERIC_TIMEZONE
      - TZ
      - N8N_ENCRYPTION_KEY
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=n8n
      - DB_POSTGRESDB_PASSWORD
      - N8N_RUNNERS_MODE=external
      - N8N_RUNNERS_AUTH_TOKEN
      - N8N_RUNNERS_BROKER_LISTEN_ADDRESS=0.0.0.0
    volumes:
      - n8n_data:/home/node/.n8n
    depends_on:
      postgres:
        condition: service_healthy

  n8n-runner:
    image: n8nio/runners:2.49.6
    restart: unless-stopped
    environment:
      - N8N_RUNNERS_TASK_BROKER_URI=http://n8n:5679
      - N8N_RUNNERS_AUTH_TOKEN
      - TZ
    depends_on:
      - n8n

  postgres:
    image: postgres:18.7
    restart: unless-stopped
    environment:
      - POSTGRES_USER=n8n
      - POSTGRES_PASSWORD
      - POSTGRES_DB=n8n
    volumes:
      - postgres_data:/var/lib/postgresql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U n8n -d n8n"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  caddy_data:
  caddy_config:
  n8n_data:
  postgres_data:
				
			

Lines under environment: with no = sign take their values from .env, so no password sits in compose.yaml and the runner never sees the database password. Each named volume, such as n8n_data, is storage Docker keeps on the server’s disk, so data survives when a container is replaced. The healthcheck holds n8n back until PostgreSQL answers, and restart: unless-stopped brings containers back after a crash or reboot, as it did after a test reboot on 1 GB.

n8n’s default database is SQLite, a built-in single-file database, but n8n recommends PostgreSQL for production, and the scaling setup later needs it. The part after the colon in each image: line is its tag, the exact version Docker downloads. The tag here is 18.7 because n8n supports PostgreSQL 16 to 18, while the untagged image now installs 19.0.

Next comes the n8n-runner container, which keeps Code-node code away from n8n’s database and credentials, and n8n’s task runners page says: “Always use task runners in production.” Its tag must match the n8n tag. In the test, a Python import sys was refused (“Security violations detected”) because standard-library imports are blocked by default.

Create Caddyfile in the same folder the same way, with nano Caddyfile, and put your subdomain in place of n8n.example.com. Caddy then gets and renews the certificate itself. The one n8n port on the host, 127.0.0.1:5678, answers only on the server itself and exists for the owner step. Figure 2 below shows how the four containers connect and which ports stay private. The flush_interval -1 line comes from n8n’s example:

				
					n8n.example.com {
	reverse_proxy n8n:5678 {
		flush_interval -1
	}
}
				
			
Self-hosted n8n Compose stack: the internet reaches only Caddy on port 443, and an SSH tunnel reaches n8n on 127.0.0.1:5678
Figure 2. Caddy is the only public way in; the SSH tunnel is a private way in that you use once.

Fill In the .env File and Back Up the Encryption Key

The .env file holds the settings that tie n8n to your address, time zone, and database, plus three secrets. One secret, the N8N_ENCRYPTION_KEY, is the encryption key n8n uses to scramble saved credentials, such as passwords for other apps, in the database, and it can’t be recreated if it’s lost. Change n8n.example.com to your own subdomain before you paste these commands, which create the file so only your user can read it:

				
					cd /home/deploy/n8n
touch .env
chmod 600 .env
cat >> .env <<'EOT'
N8N_HOST=n8n.example.com
N8N_WEBHOOK_URL=https://n8n.example.com/
GENERIC_TIMEZONE=America/Vancouver
TZ=America/Vancouver
EOT
				
			

Next, openssl writes the three secrets straight into .env, and the third line stores one database password under the names PostgreSQL and n8n expect. The last line prints nothing when Compose can read both files. It doesn’t warn about a setting missing from .env, so a misspelled name shows up later as an empty setting:

				
					openssl rand -hex 32 | sed 's/^/N8N_ENCRYPTION_KEY=/' >> .env
openssl rand -hex 32 | sed 's/^/N8N_RUNNERS_AUTH_TOKEN=/' >> .env
openssl rand -hex 32 | sed 's/.*/POSTGRES_PASSWORD=&\nDB_POSTGRESDB_PASSWORD=&/' >> .env
sudo docker compose config --quiet
				
			

Table 3 explains each setting and where it lives.

Setting Where it's set What it does
N8N_HOST
.env
Your n8n subdomain, such as n8n.example.com
N8N_PROTOCOL=https, N8N_PORT=5678
compose.yaml
Tell n8n it’s served over HTTPS and listens on port 5678 inside Docker
N8N_WEBHOOK_URL
.env
The public address n8n puts at the start of every webhook URL it shows
N8N_PROXY_HOPS=1
compose.yaml
Tells n8n that one reverse proxy, Caddy, sits in front of it, so n8n trusts the details Caddy passes on
GENERIC_TIMEZONE, TZ
.env
The time zone for schedules and for the container’s clock
DB_TYPE, DB_POSTGRESDB_*
compose.yaml, password in .env
Connect n8n to the PostgreSQL container
POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB
compose.yaml, password in .env
Create the database and its user on the first start
N8N_RUNNERS_MODE, N8N_RUNNERS_AUTH_TOKEN, N8N_RUNNERS_BROKER_LISTEN_ADDRESS
compose.yaml, token in .env
Send Code nodes to the external runner, which proves who it is with the shared token
N8N_ENCRYPTION_KEY
.env
Encrypts saved credentials in the database

Without GENERIC_TIMEZONE, n8n uses New York time, so set it and TZ to your zone, such as America/Vancouver, America/Toronto, or America/Halifax. Older guides use WEBHOOK_URL, deprecated in 2.35.0. The test found it still accepted, with a warning: “WEBHOOK_URL -> Use N8N_WEBHOOK_URL instead, which sets the base URL for both test and production webhooks.”

The first start writes the N8N_ENCRYPTION_KEY into a config file in the n8n_data volume. When the test changed the N8N_ENCRYPTION_KEY in .env, n8n refused to start (“Mismatching encryption keys”). Losing the n8n_data volume is less serious because n8n rebuilt config from .env and the credentials still worked, but any binary files stored there would be gone.

In n8n’s words, without the N8N_ENCRYPTION_KEY “a restored database or encrypted credential export can’t be decrypted”. Run grep N8N_ENCRYPTION_KEY .env and save the line in a password manager, away from the server. Every n8n process sharing this database needs the same N8N_ENCRYPTION_KEY, which matters again when you scale.

Create the Owner Account Before the Site Goes Public

Whoever opens a new n8n instance first becomes its owner. A fresh instance shows an owner setup screen, and in n8n’s words, “the first person to complete it becomes the owner.” So create the owner through a private SSH tunnel before Caddy puts n8n online, starting every container except Caddy:

				
					sudo docker compose up -d postgres n8n n8n-runner
				
			

The first start sets up the database: about four minutes on 1 GB in N6 Cloud’s test, against under a minute for restarts on 2 GB and 4 GB. Watch for “Editor is now accessible” in sudo docker compose logs -f n8n, then press Ctrl+C to stop following the log, which leaves n8n running. Next, from your own computer, open the tunnel, which carries port 5678 to the server over SSH:

				
					ssh -L 5678:127.0.0.1:5678 deploy@203.0.113.10
				
			

With that session open, browse to http://localhost:5678 and fill in the owner form, with a password of eight or more characters including a number and a capital letter. Sign up for the free registered key here if you want it. Then close the tunnel by typing exit in its terminal, and run sudo docker compose up -d on the server to start Caddy. In the test, Caddy had its certificate 22 seconds later and sent plain HTTP visitors to HTTPS.

Test a Webhook From Outside Before You Build Real Workflows

A two-node workflow called from another computer proves that n8n gives out the right webhook address and answers on it. Use a Webhook node (path n6-test, method POST) and a Respond to Webhook node returning {"ok":true}. The Webhook node’s test URL (/webhook-test/) answers one call after you click Execute workflow, and its production URL (/webhook/) works once the workflow is published. Publish it and call the production URL from your computer:

				
					curl -sS -X POST https://n8n.example.com/webhook/n6-test -H 'Content-Type: application/json' -d '{"hello":"n6"}'
				
			

In N6 Cloud’s test on 1 GB, 10 of 10 calls from a separate computer returned {"ok":true}, the first in 0.78 seconds and the rest in about a quarter of a second. Called while the editor wasn’t listening, the test URL returned a 404 that explains itself. This is the response as n8n returned it:

				
					{"code":404,"message":"The requested webhook \"n6-test\" is not registered.","hint":"Click the 'Execute workflow' button on the canvas, then try again. (In test mode, the webhook only works for one call after you click this button)"}
				
			

The address the node shows is the other check. In the test, removing N8N_WEBHOOK_URL made it https://n8n.example.com:5678/, which outside apps can’t reach, and adding N8N_HOST=localhost made it https://localhost:5678/, so set N8N_WEBHOOK_URL. If a call hangs, check the DNS record, read sudo docker compose logs caddy, and confirm that the workflow is published.

Securing a public n8n instance: Caddy is the only open door, port 5678 stays sealed, and 2FA and an audit guard the inside

Securing a Public n8n Instance

A public n8n instance needs protection at the network, where only Caddy should be reachable, and inside n8n. The Compose stack handles most of the network side, and n8n 2.x much of the inside by default. Your job is to check those defaults, then add two-factor authentication (2FA, a one-time code from a phone app at each login) and an audit.

Keep Port 5678 Off the Public Internet

The n8n rule is short: “Don’t expose the n8n process directly to the internet.” Port 5678 serves the editor, the API, and webhooks over plain HTTP, without Caddy’s HTTPS. This guide publishes it only on the server’s loopback address, 127.0.0.1, as the test server showed:

				
					sudo docker compose ps --format "{{.Name}} {{.Ports}}"
				
			

Only Caddy listens on every address, and ports 5432 and 5679 aren’t published. The official n8n Caddy example, the n8n-docker-caddy repository, publishes 5678:5678 on every address instead. N6 Cloud ran its n8n service with UFW allowing only 22, 80, and 443, then opened 5678 in the cloud firewall for about 90 seconds. From another computer, 5678 answered past UFW:

				
					curl -I http://203.0.113.10:5678/
				
			

There, n8n’s settings reported "showSetupOnFirstLoad":true, so a stranger could have claimed the owner account. Docker’s published ports skip UFW, as the Docker guide explains. The example also used an untagged image and no external task runner, and n8n’s example for Traefik, another reverse proxy, opens Traefik’s dashboard without a login (--api.insecure=true). This guide’s files avoid all of these, so there’s nothing to change.

Check n8n’s Safe Defaults, Then Add 2FA and an Audit

n8n 2.x already blocks its riskiest features. In N6 Cloud’s test, the Execute Command node (it runs shell commands) couldn’t be published (“Unrecognized node type”), file nodes couldn’t read outside n8n’s allowed folder, and Code nodes couldn’t read environment variables. The public API answered 401 to anonymous requests, and N8N_PUBLIC_API_DISABLED=true turned that into 404. Because compose.yaml passes the n8n container only the settings it lists, extra settings go at the end of the n8n service’s environment: list, followed by sudo docker compose up -d. These two lines turn off the public API, if you don’t use it, and n8n’s usage data:

				
					      - N8N_PUBLIC_API_DISABLED=true
      - N8N_DIAGNOSTICS_ENABLED=false
				
			

NODES_EXCLUDE, the list of blocked nodes, goes in the same list, with a trap: it replaces n8n’s default list instead of adding to it. When the test set it to block only Read/Write Files from Disk, Execute Command came back and ran id; hostname in the container. A custom list must repeat n8n-nodes-base.executeCommand and n8n-nodes-base.localFileTrigger. The allowed file folder, /home/node/.n8n-files, doesn’t exist in the image either. Before workflows write files, add - n8n_files:/home/node/.n8n-files under the n8n service’s volumes: and n8n_files: under the top-level volumes:, then restart as above. Finally, hand the folder to n8n’s user with sudo docker compose exec -u root n8n chown node:node /home/node/.n8n-files.

Making 2FA compulsory takes a Business or Enterprise licence, so on the Community edition each user turns it on in Personal settings with an authenticator app and keeps the 10 recovery codes. In the test, a password-only login was then refused with “MFA Error”. Don’t share the owner login, and if someone loses their phone and recovery codes, switch their 2FA off from the server:

				
					sudo docker compose stop caddy n8n-runner n8n
sudo docker compose run --rm n8n mfa:disable --email=owner@example.com
sudo docker compose up -d
				
			

The security audit also runs as a one-off container with n8n stopped, since on 1 GB both commands crashed for lack of memory beside the live instance. It covers five areas (credentials, the database, the file system, nodes, and the instance) and prints only those with findings. In the test it took 36 seconds:

				
					sudo docker compose stop caddy n8n-runner n8n
sudo docker compose run --rm n8n audit
sudo docker compose up -d
				
			

It flagged an unused credential, webhooks without authentication, and the Code, HTTP Request, and Execute Command nodes as risky. The nodes are normal to use, but an unprotected webhook answers anyone who learns its address. The Webhook node’s Authentication option closes that gap for workflows that handle sensitive data.

An n8n backup leaving the server: a PostgreSQL dump and the n8n_data volume sealed in capsules, ready to restore or roll back

Backups, Updates, and Rollbacks

Back up the database, the n8n_data volume, and your settings files, then restore them once to prove the backup works. Take a fresh backup before every update, because restoring it undoes a bad one. Without a tested backup, a failed server takes your workflows and credentials with it.

What to Back Up, and Prove the Restore Works

A complete n8n backup has three parts: a PostgreSQL dump, an n8n_data archive, and copies of your settings files. It counts only once you’ve restored it, as described below. Table 4 shows what each part protects, plus n8n’s optional export, which isn’t a full backup.

Part What it holds Why you need it
PostgreSQL dump (n8n.dump)
Workflows, encrypted credentials, users, and execution history
Almost everything you’ve built lives in the database
n8n_data archive (n8n_data.tgz)
The config file with the encryption key, event logs, and stored binary files
Needed even with PostgreSQL, because the credentials in the dump can’t be decrypted without the N8N_ENCRYPTION_KEY
.env, compose.yaml, and Caddyfile
Your settings and the three secrets
Rebuild the same stack on any server
n8n’s CLI export (optional)
Workflows and credentials as separate files
Useful for moving single workflows, but it leaves out users, executions, variables, and the encryption key

Create a private backup folder and run the backup from the project folder, where Compose names the volume n8n_n8n_data. The n8n and runner containers stop briefly during the archive, as they did for the archive the test restored. That way no file changes mid-copy:

				
					mkdir -p -m 700 /home/deploy/backup
cd /home/deploy/n8n
sudo docker compose exec -T postgres pg_dump -U n8n -d n8n -Fc > /home/deploy/backup/n8n.dump
sudo docker compose stop n8n-runner n8n
sudo docker run --rm -v n8n_n8n_data:/data:ro -v /home/deploy/backup:/backup alpine:3.24.4 tar czf /backup/n8n_data.tgz -C /data .
cp .env compose.yaml Caddyfile /home/deploy/backup/
sudo docker compose up -d
				
			

On N6 Cloud’s small test instance, the dump took 2.9 seconds and came to 0.7 MB, and the archive was under 3 KB. Run the same commands on a schedule, for example nightly with Linux’s built-in cron scheduler, and copy the folder off the server, ideally to storage in Canada. Keep that copy private: the dump together with .env or the n8n_data archive, which both hold the encryption key, opens every saved credential.

Restoring runs in reverse: empty both volumes, restore the database, then the archive, and start again. The until line waits for PostgreSQL to accept connections, and docker volume create makes the empty volume for the archive. The drill deletes your data, so try it on a test server first:

				
					cd /home/deploy/n8n
sudo docker compose down
sudo docker volume rm n8n_postgres_data n8n_n8n_data
sudo docker compose up -d postgres
until sudo docker compose exec -T postgres pg_isready -U n8n -d n8n; do sleep 1; done
sudo docker compose exec -T postgres pg_restore -U n8n -d n8n --clean --if-exists < /home/deploy/backup/n8n.dump
sudo docker volume create n8n_n8n_data
sudo docker run --rm -v n8n_n8n_data:/data -v /home/deploy/backup:/backup alpine:3.24.4 tar xzf /backup/n8n_data.tgz -C /data
sudo docker compose up -d
				
			

Compose then warns at each start that the volume “already exists but was not created by Docker Compose”, which stopped nothing in the test. The restore took 155 seconds on 1 GB. Afterwards, every workflow was published, the webhook answered, and the credential decrypted. n8n’s backup and restore page lists the same parts.

Update n8n Safely, and Roll Back With the Database

Updating n8n takes one tag change, but rolling back needs the pre-update dump: a new version can change the database, and n8n’s update page says changing the tag back doesn’t reverse that. Back up first, read the release notes, and update at least monthly, as n8n asks, on stable 2.x while 3.0 is in early access. These are the commands N6 Cloud’s test ran to go from 2.48.8 to 2.49.6, so put your current version first and the new one second in the sed line:

				
					cd /home/deploy/n8n
sed -i 's/:2.48.8/:2.49.6/g' compose.yaml
sudo docker compose pull
sudo docker compose up -d
				
			

The sed line changes n8n and the runner together, since their tags must match. The update ran 13 migrations (changes to the database’s structure), and the instance was offline for about 225 seconds on 1 GB while n8n started. A docker compose down before up -d, which n8n’s update steps add, made no difference. This query shows the newest migration:

				
					sudo docker compose exec -T postgres psql -U n8n -d n8n -t -A -c 'SELECT name FROM migrations ORDER BY id DESC LIMIT 1;'
				
			

Run it before and after an update to see whether migrations ran. In the test, a tag-only rollback to 2.48.8 started without warning and served webhooks on a database 13 migrations newer than it knows (Figure 3). The safe rollback is the previous section’s restore after changing both tags back. n8n’s db:revert command, which undoes one migration per run, is an alternative for experienced users.

n8n update and two rollbacks: a tag-only rollback leaves the database 13 migrations ahead; the pre-update dump matches it
Figure 3. A tag-only rollback leaves the newer database in place without any warning; only the pre-update dump brings it back.

Keep the rest of the stack current too. Install Ubuntu’s security updates regularly with the same apt update step as in the server preparation. Update PostgreSQL and Caddy the way you update n8n, by changing their pinned tags after a backup. Keep PostgreSQL on major version 18, though: n8n doesn’t list 19 as supported, and a new major version can’t use the old data files without a dump and restore.

When One Server Isn’t Enough Anymore

When n8n runs out of room, fix the heavy workflow first, then add memory, and only then add queue mode, which hands executions to separate workers. n8n documents a “JavaScript heap out of memory” error, where the heap is the memory n8n’s JavaScript engine uses for its data, including the items a workflow handles. In N6 Cloud’s test that error never appeared, but two other messages did. Search the log for them:

				
					sudo docker compose logs n8n | grep -E "TaskRunnerDisconnectedError|Last session crashed"
				
			

In the test, TaskRunnerDisconnectedError appeared when a Code node overwhelmed the task runner, and the webhook caller got {"message":"Error in workflow"}. “Last session crashed” means n8n’s previous run ended without a clean shutdown. Here, that happened each time the system’s out-of-memory killer stopped n8n and Docker restarted it.

n8n’s memory issues page suggests splitting large jobs, for example, 200 rows per execution instead of 10,000. Sent in batches of 200 to a sub-workflow with the Loop Over Items node, the 200,000-item job that had failed on 2 GB finished in 441 seconds. On 1 GB, the fix failed without swap and, with a 2 GB swap file (disk space used as overflow memory), finished only at 50,000 items. On 2 GB, adding - NODE_OPTIONS=--max-old-space-size=1024 to n8n’s environment: list, which caps that heap for n8n’s main process, also let the job finish in one run.

If your workflows are lean, a bigger server is next; the guide to vertical vs horizontal scaling compares that with adding servers. N6 Cloud’s VPS page says you can add CPU, RAM, or NVMe storage (fast solid-state drives) from the portal without reinstalling. N6 Cloud’s upgrade notes say the VPS restarts with about a minute offline and can’t be downgraded. In the test, the n8n stack came back by itself each time the resized server started.

Queue mode splits n8n into parts: a main instance takes triggers, Redis (an in-memory data store) queues executions, and workers run them. They all share PostgreSQL and the same N8N_ENCRYPTION_KEY. n8n’s edition comparison includes it in Community, but its pricing page lists “Queue mode for scaling” under Business, so confirm with n8n first. In N6 Cloud’s test, it ran on Community with no licence key. It costs memory first: on 4 GB, one worker and Redis added 283 MiB at idle (about 31% more), and throughput on the same two vCPUs fell. With 5 webhook calls at a time, it dropped from 13.4 to 10.0 requests per second, and with 10 at a time, from 13.9 to 11.5. On 1 GB, it couldn’t run. Its gain will likely come only when workers have their own CPU.

An N6 Cloud VPS in a BC data centre with full root access and NVMe storage, keeping n8n's workflow data in Canada

Run n8n on an N6 Cloud VPS and Keep Your Data in Canada

Self-hosted n8n keeps its data wherever its server is, so n8n VPS hosting in Canada means a Canadian server. The pricing FAQ on n8n’s website says hosted-plan data “is stored within the EU, on servers located in Frankfurt, Germany”. N6 Cloud is Canadian-owned, founded in British Columbia (BC), and every VPS it sells runs in BC data centres, so your credentials, execution history, and n8n_data volume stay in Canada.

Location matters because data in another country can be accessed under its laws. The Office of the Privacy Commissioner of Canada’s guidelines for processing personal data across borders say such information “may be accessed by the courts, law enforcement and national security authorities”. A Canadian server doesn’t change what your workflows send to outside services, and this guide isn’t legal advice.

An unmanaged N6 Cloud VPS suits this guide, with full root access and no control panel, so Docker manages its own ports. N6 Cloud’s managed VPS comes with a control panel, and Docker isn’t recommended alongside it. Every VPS runs on KVM, a virtualization technology that gives each VPS its own full operating system, with NVMe storage. For a short test instance, an hourly-billed cloud server costs only the hours until you delete it.

Backups can stay in Canada too: N6 Cloud’s optional Cloud Backup add-on, not enabled by default, stores copies in the same BC data centre. The Terms of Service still make you responsible for copies outside N6 Cloud’s network, the off-server copy the backup section asks for. Support answers tickets and phone calls 24/7, with live chat 9:00 AM to 5:00 PM Pacific.

To build this stack, start with unmanaged VPS hosting from N6 Cloud, choose Ubuntu 26.04 LTS, and pick the size from the sizing section. The VPS hosting page lists the current price of each size, so you can set it against your n8n Cloud bill. Every VPS plan includes a 30-day money-back guarantee.

Frequently Asked Questions

Is self-hosted n8n really free?

Yes, the Community edition costs nothing and needs no licence, so the server is your only bill. A free registered key unlocks extras such as folders. Team features need a paid licence.

Does self-hosted n8n limit the number of executions?

No. As the section on what self-hosting means explains, n8n states no execution quota for the Community edition. Paid licence keys report production executions to n8n daily, but on your own server the practical limit is memory.

Do I need Linux experience to self-host n8n?

You need some: enough to paste commands into a terminal, read the output, and spot when it doesn’t match the guide. On an unmanaged VPS, keeping the server updated and secure after setup is your job. If you’d rather not do it yourself, N6 Cloud’s hourly server management covers tasks inside an unmanaged VPS.

Can I run n8n on the same VPS as WordPress?

Yes, if the memory adds up. In N6 Cloud’s tests, this guide’s four containers used about 380 MiB at idle, and WordPress with MariaDB used 331 MiB in the Docker guide’s test. Both can sit behind one Caddy on separate subdomains, but size the server for both at their busiest.

How do I move n8n to a new VPS?

Copy the backup folder to /home/deploy/backup and the settings files into /home/deploy/n8n on the new server, so the same N8N_ENCRYPTION_KEY comes with them. Then run the restore steps without the down and volume rm lines, and switch the DNS record last. From n8n Cloud, download each workflow from the editor as a file and import it on the new instance. The file names its credentials but doesn’t hold their secrets, so create each credential again and publish each workflow.

Can n8n run AI agent workflows on a small VPS?

Yes, as long as the AI model runs elsewhere. A workflow calling an outside AI service sends a request and waits, leaving the heavy work to that provider. Running a model locally needs far more memory: n8n’s Assistant sandbox alone asks for at least 4 GB of RAM and 2 vCPUs, which n8n intends only for development and testing.

Related Posts