To self-host n8n on a VPS, create a small Linux server, install Docker, point a subdomain at it, and run n8n behind a reverse proxy with Docker Compose. The official n8n docs use Traefik for automatic HTTPS. This guide walks through that official path, then covers backups, updates and the mistakes that most often cost people their data.
Commands and file contents below follow the n8n documentation as read in November 2026. n8n releases frequently, so check the docs for the current stable version before you deploy.

Should you self-host n8n at all?
n8n itself says self-hosting is meant for people who are comfortable with servers. Its documentation lists the prerequisites: setting up servers and containers, managing resources and scaling, securing servers and applications, and configuring n8n. It warns that mistakes can lead to data loss, security issues and downtime, and recommends n8n Cloud if you are not experienced at managing servers (source: n8n Docker Compose guide).
Self-hosting makes sense when:
You want to keep workflow data and credentials on infrastructure you control.
You are comfortable with SSH, DNS and Docker, or have someone who is.
You want predictable infrastructure costs instead of per-plan limits.
Stay on n8n Cloud if nobody on your team wants to own updates, backups and uptime.
What you need before you start
Item | Notes |
|---|---|
A Linux VPS | n8n's Hetzner guide says the CPX11 type is enough for most usage levels. If you plan to add the n8n Assistant, it recommends at least 4 GB RAM and 2 vCPU. Check your provider's current plans and prices. |
A domain you control | You will create a subdomain such as |
SSH access | Key-based login is safer than passwords. |
Docker Engine and Docker Compose | Installed in step 1 below. |
Providers n8n documents deployment guides for include Hetzner and DigitalOcean. Any plain Linux VPS that can run Docker works the same way.

Step 1: Install Docker and Docker Compose
Follow the official instructions for your distribution: Docker Engine and Docker Compose. Then verify:
docker --version
docker compose version Optionally let your user run Docker without sudo:
sudo usermod -aG docker ${USER}
exec sg docker newgrp Step 2: Point a subdomain at the server
In your DNS provider, add an A record:
Record type | Name | Destination |
|---|---|---|
A |
| your server's IP address |
Wait for DNS to propagate before starting the stack. The TLS certificate request in step 5 fails if the name does not resolve to your server yet.
Step 3: Create the project folder and .env file
mkdir n8n-compose
cd n8n-compose
mkdir local-files Create a .env file in that folder and change the values to your own:
DOMAIN_NAME=example.com
SUBDOMAIN=n8n
GENERIC_TIMEZONE=Europe/Berlin
SSL_EMAIL=you@example.com DOMAIN_NAME and SUBDOMAIN together set where n8n is reachable (here https://n8n.example.com). GENERIC_TIMEZONE controls scheduling nodes such as the Schedule Trigger. SSL_EMAIL is used for the Let's Encrypt certificate.
Step 4: Create compose.yaml
This is the configuration from the n8n documentation. It runs two containers: n8n, and Traefik, a proxy that handles routing and TLS certificates.
services:
traefik:
image: "traefik"
restart: always
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.web.http.redirections.entryPoint.to=websecure"
- "--entrypoints.web.http.redirections.entrypoint.scheme=https"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true"
- "--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}"
- "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json"
ports:
- "80:80"
- "443:443"
volumes:
- traefik_data:/letsencrypt
- /var/run/docker.sock:/var/run/docker.sock:ro
n8n:
image: n8nio/n8n
restart: always
ports:
- "127.0.0.1:5678:5678"
labels:
- traefik.enable=true
- traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`)
- traefik.http.routers.n8n.tls=true
- traefik.http.routers.n8n.entrypoints=web,websecure
- traefik.http.routers.n8n.tls.certresolver=mytlschallenge
- traefik.http.middlewares.n8n.headers.SSLRedirect=true
- traefik.http.middlewares.n8n.headers.STSSeconds=315360000
- traefik.http.middlewares.n8n.headers.browserXSSFilter=true
- traefik.http.middlewares.n8n.headers.contentTypeNosniff=true
- traefik.http.middlewares.n8n.headers.forceSTSHeader=true
- traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME}
- traefik.http.middlewares.n8n.headers.STSIncludeSubdomains=true
- traefik.http.middlewares.n8n.headers.STSPreload=true
- traefik.http.routers.n8n.middlewares=n8n@docker
environment:
- N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
- N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
- N8N_PORT=5678
- N8N_PROTOCOL=https
- NODE_ENV=production
- N8N_WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
- GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
- TZ=${GENERIC_TIMEZONE}
- N8N_RESTRICT_FILE_ACCESS_TO=/files
volumes:
- n8n_data:/home/node/.n8n
- ./local-files:/files
volumes:
n8n_data:
traefik_data: Two details worth knowing. N8N_WEBHOOK_URL is available from n8n 2.30.0; on earlier versions the variable is WEBHOOK_URL. And the n8n_data volume holds n8n's SQLite database and encryption key, so it is the thing you must never lose.
Step 5: Start it
sudo docker compose up -d Open https://n8n.example.com (your own subdomain). n8n is only reachable over HTTPS in this setup. To stop the containers, run sudo docker compose stop. If the page does not load, check your firewall (ports 80 and 443 must be open) and your DNS record.
Back up before you need it
This is the step people skip. According to the n8n backup documentation, a complete backup has two parts:
The
.n8nfolder. It holds theconfigfile with the credential encryption key and, with the default SQLite database, the database file. In Docker this is then8n_datavolume.Your external database, if you use PostgreSQL instead of SQLite. The
.n8nfolder is still required because credentials are encrypted with the key it holds.
Two warnings from the same page: with SQLite, stop n8n before copying the folder, because copying a database that is being written to can give you an inconsistent backup. And without the encryption key, restored credentials cannot be decrypted.
You can also export workflows and credentials with the CLI:
n8n export:workflow --backup --output=backups/workflows/
n8n export:credentials --backup --output=backups/credentials/ These exports do not include users, execution history, variables or instance settings, so they are enough to move workflows between instances but not to recover a whole server. Inside Docker, mount a host directory for the output or copy the files out, because only the .n8n folder is on a volume. Store at least one copy off the server.
Updating n8n
n8n releases a new minor version most weeks, with a stable channel for production and a beta channel for the newest release. Take a backup first (n8n recommends a full backup before updating), then pull the new image and recreate the containers:
sudo docker compose pull
sudo docker compose up -d Read the n8n update guide for version-specific notes before jumping several releases. For production use, consider pinning the n8nio/n8n image to a specific version tag instead of the floating default, so updates happen when you choose.
Common mistakes
No backup of the encryption key. Workflows survive without it; credentials do not.
DNS not ready. Traefik cannot obtain a certificate if the subdomain does not point at the server.
Closed ports. Ports 80 and 443 must be reachable for HTTPS and certificate issuance.
Running beta in production. Stick to the stable version for workflows that matter.
Leaving the Traefik dashboard exposed. The sample uses
--api.insecure=true, which is convenient for a first run. Review it before relying on this server for anything sensitive.
FAQ
How much does it cost to self-host n8n? The software is free to run for your own use under n8n's license terms, so the main cost is the VPS. Prices change often, so check your provider's current pricing page rather than relying on a number in a guide.
How big a VPS do I need for n8n? n8n's Hetzner guide says the CPX11 plan is enough for most usage levels, and recommends at least 4 GB RAM and 2 vCPU if you add the n8n Assistant. Heavy workflows with large data may need more.
Does n8n need PostgreSQL? No. By default n8n stores credentials, executions and workflows in SQLite. PostgreSQL is supported through environment variables, and the n8n Docker documentation describes how to configure it.
Can I run n8n without a domain name?
The Docker Compose setup above assumes a subdomain so it can issue a TLS certificate. For local testing, the plain Docker install exposes n8n on http://localhost:5678.
Is self-hosted n8n secure? It is as secure as you keep it: HTTPS, a firewall, SSH keys, regular updates and backups are your responsibility. That is why n8n recommends Cloud for people who are not experienced at managing servers.
Need help setting it up?
If you would rather have workflows running than maintain a server, Kavio can set up and harden a self-hosted n8n instance, build the automations on top of it, or integrate it with your existing website. See our services or get in touch.

