Self-host n8n: your automations on your own server

When you self-host n8n, your automations, their credentials and their history run on a machine you control, with the free Community edition. This guide follows the official n8n documentation, from the licence to backups, by way of Docker, PostgreSQL, HTTPS webhooks and queue mode.

Simon Vasconcelos Lee By Published on 2 December 20269-minute read

All guides AI and automation

In short

  1. The n8n licence allows free use for your company’s internal business purposes, including automations delivered to your clients, as long as they can neither create nor modify them.
  2. Install n8n with Docker Compose, and use PostgreSQL as soon as the instance serves in production.
  3. Set the N8N_ENCRYPTION_KEY and back it up separately: without it, saved credentials can no longer be decrypted.
  4. Webhooks need a public HTTPS address, declared in N8N_WEBHOOK_URL, behind a reverse proxy.
  5. As the load grows, queue mode spreads executions across workers, through Redis. Update at least once a month.

What the n8n licence allows

n8n is published under the Sustainable Use License, a "fair-code" licence the company created in 2022: the source code is available, with usage limits that place it outside the OSI’s definition of open source. It allows you to use, modify and redistribute n8n, with three limits. The first, word for word: "You may use or modify the software only for your own internal business purposes or for non-commercial or personal use." The other two: redistribute only free of charge and for non-commercial purposes, and keep the licence notices.

Allowed by the licenceRequires a commercial agreement with n8n
Automating how your company runsHosting n8n as a service where your clients build their workflows
Delivering automations to your clients on your instance, without them being able to create or modify themLetting external users configure their workflows (interface, API, MCP, AI agent)
Charging for setup, maintenance, training and consultingOffering n8n as a white-label product
Using n8n behind the scenes in your product, with your users triggering your automationsLaunching your own automation product on the n8n code
Running several instances of the Community editionUsing Enterprise features without a licence

The Community edition covers almost all of n8n, queue mode included; the paid Business and Enterprise plans add, among other things, SSO, projects, workflow sharing and multi-main mode. For a borderline case, the company’s licence FAQ goes through examples.

Installing with Docker Compose

n8n recommends Docker for self-hosting: an isolated environment, with no conflicts with the system, and a database and variables that are simple to manage. Here is a minimal Docker Compose base for n8n and PostgreSQL, whose secrets live in a .env file alongside:

compose.yaml
services:
  postgres:
    image: postgres:18
    restart: always
    environment:
      POSTGRES_USER: n8n
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: n8n
      PGDATA: /var/lib/postgresql/data
    volumes:
      - db-storage:/var/lib/postgresql/data

  n8n:
    image: n8nio/n8n:${N8N_VERSION}
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      DB_TYPE: postgresdb
      DB_POSTGRESDB_HOST: postgres
      DB_POSTGRESDB_DATABASE: n8n
      DB_POSTGRESDB_USER: n8n
      DB_POSTGRESDB_PASSWORD: ${POSTGRES_PASSWORD}
      N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
      N8N_HOST: n8n.example.com
      N8N_PROTOCOL: https
      N8N_WEBHOOK_URL: https://n8n.example.com/
      N8N_PROXY_HOPS: "1"
      GENERIC_TIMEZONE: Europe/Paris
      TZ: Europe/Paris
    volumes:
      - n8n-data:/home/node/.n8n
    depends_on:
      - postgres

volumes:
  db-storage:
  n8n-data:

In terms of resources, n8n puts little load on the processor, and memory depends on the workflows: an idle n8n Cloud instance uses about 100 MB, while the Code node and large binary files need much more. The company’s full Docker Compose stack, with the n8n Assistant sandbox, needs at least 4 GB and 2 vCPUs.

The n8n documentation lists what self-hosting involves: installing servers and containers, managing resources and scaling, securing servers and applications, configuring n8n. On a Managed VPS, the host takes on the server share of that list: system and security updates, day-and-night monitoring, backups. It also proactively monitors your instance, errors, slowdowns, disk space, and recommends the fixes, which you apply, yourself or through your AI assistant.

SQLite or PostgreSQL

By default, n8n stores workflows, credentials and executions in SQLite, a single file (~/.n8n/database.sqlite). Its documentation considers it suited to trials, and advises PostgreSQL as soon as a production instance serves more than a handful of users or runs workflows continuously. It supports PostgreSQL 16, 17 and 18.

CriterionSQLitePostgreSQL
SetupNone, the default databaseOne more service and its DB_POSTGRESDB_* variables
UseTrials, a small instanceProduction, continuous executions
Queue modeOutside its scopeRequired
BackupA copy of the .n8n folder, with n8n stoppedpg_dump, with n8n running

An existing SQLite instance moves to PostgreSQL through n8n’s export and import commands, the new database starting empty. With the postgres:18 image, keep the PGDATA line from the example: without it, PostgreSQL 18 stores its data outside the volume.

n8n automatically prunes executions that finished more than 14 days ago, or beyond 10,000. With SQLite, the freed space is reused; to give it back to the disk, enable DB_SQLITE_VACUUM_ON_STARTUP.

Webhooks: a domain name and HTTPS

A webhook is an address that external services call: n8n must be reachable from the internet. It builds its addresses from N8N_PROTOCOL, N8N_HOST and N8N_PORT, whereas the public arrives through the proxy, on port 443. Its documentation calls for three settings:

Nginx block, /etc/nginx/sites-available/n8n
server {
    listen 80;
    server_name n8n.example.com;

    location / {
        proxy_pass http://127.0.0.1:5678;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

HTTPS is a must from the start: by default, n8n sends its cookies over HTTPS only (N8N_SECURE_COOKIE=true). sudo certbot --nginx installs the Let's Encrypt certificate, which Certbot then renews on its own. The Upgrade and Connection headers serve the editor, which receives its updates over WebSocket.

When the load grows: queue mode

On a single instance, n8n handles up to 220 workflow executions per second, according to the company’s measurements. The first limit usually comes from memory: each node fetches as much data as it asks for, and binary files stay in memory by default. The company’s advice: N8N_DEFAULT_BINARY_DATA_MODE=filesystem to write those files to disk, batches of 200 rows rather than 10,000, the Code node kept for what truly needs it, sub-workflows, or more memory.

Queue mode, included in the Community edition, then separates the roles: the main instance receives triggers and webhooks, Redis holds the execution queue, and workers run the executions.

SettingWhereRole
EXECUTIONS_MODE=queueMain instance and workersTurns on queue mode
QUEUE_BULL_REDIS_HOST, QUEUE_BULL_REDIS_PORTMain instance and workersRedis address, localhost:6379 by default
N8N_ENCRYPTION_KEYEverywhere, identicalLets workers read the credentials
n8n worker --concurrency=10Each workerParallel executions: 10 by default, at least 5 recommended

This mode relies on PostgreSQL, and binary files move into the database (N8N_DEFAULT_BINARY_DATA_MODE=database) rather than onto one instance’s disk. For very large volumes of incoming calls, dedicated webhook processes, behind a load balancer, complete the setup.

Encryption key, backups and updates

n8n encrypts saved credentials (API keys, passwords, tokens) with a key generated at first launch and stored in the config file of the .n8n folder. Without that key, or without the same N8N_ENCRYPTION_KEY, a restored database or a credentials export can no longer be decrypted. Set the key before the first launch, and keep a copy of it separately, in a password manager.

A complete backup brings together:

Terminal, in the compose.yaml folder
docker compose exec -T postgres pg_dump -U n8n -Fc n8n > n8n-$(date +%F).dump
docker compose exec n8n n8n export:workflow --backup --output=/home/node/.n8n/backups/workflows/
docker compose exec n8n n8n export:credentials --backup --output=/home/node/.n8n/backups/credentials/

The exports cover workflows and credentials, still encrypted with the key; users, execution history, variables and settings stay in the database. They therefore complement its backup. A reimported workflow arrives deactivated.

Updating

n8n publishes a minor version almost every week. Its documentation advises updating at least once a month, to avoid big jumps, reading the release notes to spot breaking changes, and trying first on a test instance. With Docker Compose, change N8N_VERSION in .env, then:

Terminal
docker compose pull
docker compose down
docker compose up -d

Schedule the update for a quiet hour: during the restart, a webhook that gets called receives an error.

Your n8n automations, on a server run for you

With a Simafri Managed VPS, our teams keep your n8n instance’s server up to date, monitor it day and night and step in without waiting for your call; they also proactively monitor your instance and recommend useful fixes, which you apply, yourself or through your AI assistant. Backups are encrypted every night and kept off the machine, restores are included, and migrating your current server is complimentary.

Explore Managed VPS

Frequently asked questions

Can n8n be used for free in a business?

Yes. The self-hosted Community edition is free for the company’s internal business purposes, under the Sustainable Use License. You can also deliver automations to your clients and charge for setting them up, as long as they can neither create nor modify the workflows.

Which database should I choose for n8n?

SQLite, the default database, is fine for trials. For a production instance with several users or workflows running continuously, the n8n documentation advises PostgreSQL (versions 16, 17 and 18), which queue mode also requires.

What happens if you lose the n8n encryption key?

Saved credentials can no longer be decrypted, neither in a restored database nor in an export: they have to be re-entered one by one. The key is in the config file of the .n8n folder, or in N8N_ENCRYPTION_KEY if you set it: back it up separately.

Why do my n8n webhooks show localhost:5678?

n8n builds its webhook addresses from N8N_PROTOCOL, N8N_HOST and N8N_PORT. Behind a reverse proxy, declare the public address in N8N_WEBHOOK_URL (WEBHOOK_URL before version 2.30) and set N8N_PROXY_HOPS=1.

Contact us