Skip to content
AE DIGITAL
AutomationBy 6 min read

How to Install n8n on a VPS with Docker: Step-by-Step with HTTPS and Backups

Install self-hosted n8n on a VPS with Docker Compose: persistent database, domain with HTTPS, encryption key, tested backups and safe upgrades.

Article cover: the word “HTTPS” next to a glowing icon on a violet space background

What a production n8n Docker install requires

Installing n8n with Docker on a VPS means running the official container with Docker Compose, behind an HTTPS reverse proxy, with persistent data, a safely stored encryption key and verified backups. The single docker run command found in many tutorials starts n8n in seconds, but solves none of these: the first restart, upgrade or server failure can wipe your workflows and credentials.

This guide is for technical freelancers and small businesses that want self-hosted n8n for internal or ecommerce automations. If you are still choosing between cloud tools, our Zapier vs Make comparison helps you decide when a managed service beats an instance you have to maintain.

Prerequisites: VPS, domain and SSH access

Before touching Docker, prepare the minimum infrastructure:

  • A Linux VPS kept up to date (for example Ubuntu LTS) with at least 2 vCPUs and 2-4 GB of RAM for a small-business load.
  • Key-based SSH access, password root login disabled and a dedicated admin user.
  • A subdomain such as n8n.yourdomain.com, with an A record pointing to the server IP.
  • A firewall allowing only SSH, 80 and 443.

Watch the firewall when using Docker

Docker's documentation warns that ports published by containers can bypass ufw or firewalld rules. If you publish 5678:5678, n8n is reachable from the internet even with the firewall on. Bind the port to the local interface with 127.0.0.1:5678:5678, as n8n's official example does, and expose only the reverse proxy.

Install Docker and Docker Compose

Install Docker Engine from Docker's own repository rather than the often outdated distribution package. On Ubuntu, the documented procedure sets up the apt repository and installs docker-ce, docker-ce-cli, containerd.io, docker-buildx-plugin and docker-compose-plugin. Verify with docker --version and docker compose version. Create a project folder such as /opt/n8n for compose.yaml, the .env file and your backup scripts.

Configure n8n with a persistent database

By default n8n uses SQLite, stored in /home/node/.n8n. For a production instance with many executions, PostgreSQL is the better choice and is officially supported (versions 16, 17 and 18 according to the docs). In the n8n service, set:

  • DB_TYPE=postgresdb
  • DB_POSTGRESDB_HOST, DB_POSTGRESDB_DATABASE, DB_POSTGRESDB_USER and DB_POSTGRESDB_PASSWORD
  • GENERIC_TIMEZONE and TZ set to your timezone, because scheduling nodes rely on it

The volume you cannot forget

Even with PostgreSQL, the documentation recommends persisting /home/node/.n8n with a named volume: it holds the encryption key and other instance files. PostgreSQL needs its own separate volume. Without volumes, every docker compose down deletes data you thought was saved.

Domain, reverse proxy and HTTPS

The Docker Compose setup published by n8n uses Traefik as the reverse proxy: it listens on 80 and 443, redirects HTTP to HTTPS and obtains TLS certificates from Let's Encrypt using the address in SSL_EMAIL. In .env you define DOMAIN_NAME and SUBDOMAIN; the n8n service gets N8N_HOST, N8N_PROTOCOL=https and the public webhook URL (N8N_WEBHOOK_URL from version 2.30, WEBHOOK_URL before that). A wrong webhook URL makes triggers display internal addresses that external services cannot call.

Caddy or Nginx work just as well: what matters is automatic certificate renewal and expiry monitoring. The same principles are covered in our guide to TLS certificates and automated renewal.

Encryption key and users

n8n encrypts credentials before saving them to the database. On first launch it generates a random key and writes it to ~/.n8n; you can set your own with N8N_ENCRYPTION_KEY. We recommend always doing so, generating a long random string and storing it in a company password manager. Restore to a new server without the same key and your credentials will be unreadable.

Accounts and access

On first login, create the owner account with a company email, not a personal one. Enable two-factor authentication in your personal settings and keep the recovery codes. Invite collaborators with individual accounts and never share the owner credentials.

Back up workflows and credentials

A reliable n8n backup has three layers:

  1. Database: pg_dump produces consistent exports even while the database is in use. Schedule it nightly with cron.
  2. Application export: with docker exec -u node, run n8n export:workflow --backup --output=... and n8n export:credentials --backup --output=.... The files stay encrypted with your key; avoid --decrypted, which writes secrets in plain text.
  3. Off-server copy: move archives to external storage with retention, for example 7 daily and 4 weekly copies.

A backup only counts if the restore works. At least once a quarter, restore to a test VPS and confirm that a workflow using credentials runs correctly. The method for setting RPO and RTO is the one described in our disaster recovery and restore testing guide.

Upgrade n8n without breaking workflows

n8n ships minor releases frequently and follows semantic versioning, so incompatible changes come with major versions. Our procedure:

  1. Pin a specific image tag in compose.yaml instead of latest.
  2. Read the release notes for every version in between.
  3. Back up the database and the exports.
  4. Change the tag, then run docker compose pull and docker compose up -d.
  5. Check logs and executions of critical workflows; if something fails, revert the tag and restore the backup.

Final security checklist

  • Port 5678 bound to 127.0.0.1; only 80 and 443 public.
  • HTTPS with automatic renewal and expiry alerts.
  • N8N_ENCRYPTION_KEY set and stored off the server.
  • Named volumes for /home/node/.n8n and PostgreSQL.
  • Nightly off-site backups and one tested restore.
  • 2FA enabled and individual accounts.
  • Pinned image tag and scheduled upgrades.

To connect the instance to your business processes, the ecommerce automations guide shows which flows to automate first. If you would rather hand automation design and maintenance to a technical team, see our Zapier, Make and n8n automation service or contact us to review your setup.

Frequently asked questions

What VPS size do I need to run n8n with Docker?

For a small business with a handful of workflows, a Linux VPS with 2 vCPUs and 2-4 GB of RAM is usually enough; scale up for heavy files or many parallel executions. An updated OS, key-based SSH and monitored disk space for the database and backups matter more than raw resources.

Should I use SQLite or PostgreSQL for self-hosted n8n?

SQLite is the default and fine for testing and light loads. For a production instance with many executions we prefer PostgreSQL, which n8n officially supports, because pg_dump gives consistent backups and it handles a growing execution history better.

What happens if I lose the n8n encryption key?

n8n uses the key to encrypt stored credentials. Without the same key, a restore on a new server cannot decrypt them and you will have to re-enter every credential manually. Set the key explicitly and keep it somewhere other than the VPS.

How do I upgrade n8n installed with Docker Compose?

Take a backup, read the release notes, change the image tag in the Compose file, then run docker compose pull and docker compose up -d. Check your critical workflows and, if something breaks, revert to the previous tag and the backup you just took.

Sources

  1. Docker Compose server setup — n8n
  2. Set a custom encryption key — n8n
  3. Supported databases and settings — n8n
  4. CLI commands for n8n — n8n
  5. Install Docker Engine on Ubuntu — Docker
  6. pg_dump — PostgreSQL Global Development Group

Related articles

Tell us what isn't working.

We reply within one business day with a first opinion and, if it makes sense, a quote.

Write to us