Log inSign up

n8n automation on a server you control

Start n8n from the official docker.n8n.io/n8nio/n8n image with Docker Compose, store data in PostgreSQL, and set N8N_HOST, WEBHOOK_URL and a fixed N8N_ENCRYPTION_KEY. Bind port 5678 to localhost, put Nginx with a Certbot certificate in front, and create the owner account on the first visit.

Topic: Self-hosted apps · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13 · Updated 2026-12-03

What should the server look like for n8n?

n8n is a Node.js application; idle it uses a few hundred megabytes, and memory climbs with the size of the data passing through each workflow. A 2 GB plan handles typical business automations, and 4 GB suits workflows that move large files or run many executions in parallel.

  • Ubuntu 24.04, Ubuntu 22.04, Debian 12 or Debian 13 with Docker and the Compose plugin (install steps).
  • A hostname, for example n8n.example.net, with A and AAAA records.
  • Your firewall allowing only SSH, 80 and 443; see UFW.

How do you write the Compose file?

Create /opt/n8n and generate two secrets: one for the database and one for credential encryption.

sudo mkdir -p /opt/n8n && cd /opt/n8n
openssl rand -hex 24
openssl rand -hex 32

Then write /opt/n8n/compose.yaml:

services:
  postgres:
    image: postgres:16
    restart: unless-stopped
    environment:
      POSTGRES_USER: n8n
      POSTGRES_PASSWORD: db-secret-here
      POSTGRES_DB: n8n
    volumes:
      - pg_data:/var/lib/postgresql/data
  n8n:
    image: docker.n8n.io/n8nio/n8n:latest
    restart: unless-stopped
    depends_on:
      - postgres
    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: db-secret-here
      N8N_HOST: n8n.example.net
      N8N_PORT: 5678
      N8N_PROTOCOL: https
      WEBHOOK_URL: https://n8n.example.net/
      N8N_PROXY_HOPS: 1
      N8N_ENCRYPTION_KEY: encryption-secret-here
      GENERIC_TIMEZONE: Europe/Berlin
      TZ: Europe/Berlin
    volumes:
      - n8n_data:/home/node/.n8n
volumes:
  pg_data:
  n8n_data:

N8N_ENCRYPTION_KEY protects every stored credential. Write it down somewhere safe: if it is lost, saved credentials cannot be decrypted, even from a backup. N8N_PROXY_HOPS tells n8n to trust one reverse proxy for client addresses.

How do you start n8n and confirm the version?

cd /opt/n8n
sudo docker compose up -d
sudo docker compose ps
sudo docker compose exec n8n n8n --version
curl -sI http://127.0.0.1:5678/healthz

The health endpoint answers with HTTP 200 once the editor is up. Logs are available with sudo docker compose logs -f n8n.

How do you put Nginx and HTTPS in front?

The editor relies on a WebSocket push connection, and webhooks can carry large bodies, so the proxy needs upgrade headers, a higher body limit and buffering switched off.

server {
    listen 80;
    listen [::]:80;
    server_name n8n.example.net;
    client_max_body_size 50m;

    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-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
        proxy_read_timeout 300s;
    }
}
sudo nano /etc/nginx/sites-available/n8n
sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d n8n.example.net

If Certbot is not installed yet, see the Certbot guide. Caddy works just as well with a one-line reverse_proxy 127.0.0.1:5678.

What happens on the first visit?

Browse to https://n8n.example.net and n8n asks you to create the owner account, which becomes the instance administrator. Use a strong password and turn on two-factor authentication in your personal settings. From the owner account you can invite more users once mail works.

Test a webhook straight away: add a Webhook node, copy its production URL, activate the workflow and call it with curl -X POST https://n8n.example.net/webhook/test-path. If the URL shown in the node starts with http://localhost, WEBHOOK_URL is missing or wrong.

How do you set up mail for invitations?

n8n mails user invitations and password reset links. Instead of sending straight to port 25, which you should only plan for after asking support in a ticket, point it at an authenticated relay on port 587 (details in the SMTP relay guide). Add these lines under environment:

      N8N_EMAIL_MODE: smtp
      N8N_SMTP_HOST: smtp.relay.example.net
      N8N_SMTP_PORT: 587
      N8N_SMTP_USER: n8n@example.net
      N8N_SMTP_PASS: relay-password
      N8N_SMTP_SENDER: n8n@example.net
      N8N_SMTP_SSL: "false"

With SSL set to false, n8n upgrades the port 587 connection through STARTTLS. Apply the change with sudo docker compose up -d. Workflows that send mail use their own Send Email node credentials and can use the same relay.

How do you back up workflows and credentials?

Two layers work well together. First, a database dump of everything:

cd /opt/n8n
sudo docker compose exec -T postgres pg_dump -U n8n n8n | gzip > n8n-$(date +%F).sql.gz

Second, the n8n CLI exports workflows and encrypted credentials as JSON files, handy for version control:

sudo docker compose exec n8n n8n export:workflow --backup --output=/home/node/.n8n/backups/workflows/
sudo docker compose exec n8n n8n export:credentials --backup --output=/home/node/.n8n/backups/credentials/

Keep the encryption key with the backup, stored separately. The daily backup add-on adds a whole-disk copy on top.

How do you update n8n?

n8n releases often. Read the release notes for breaking changes, then:

cd /opt/n8n
sudo docker compose pull n8n
sudo docker compose up -d
sudo docker compose exec n8n n8n --version

For production, pin a version tag such as a specific 1.x or 2.x release instead of latest, and step through major versions one at a time, following the migration notes for each.

What goes wrong most often?

  • Editor shows "Connection lost": WebSocket headers are missing in the proxy.
  • Webhooks return 404: the workflow is not active, or you called the test URL while the editor was not listening.
  • Credentials fail to decrypt after a move: the new server uses a different N8N_ENCRYPTION_KEY.
  • Memory errors on big files: split the data into batches or move to a larger plan following move to a larger plan.

For a wider view of running your own apps, see self-hosting.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-2personal automations and webhooks1 vCPU, 2 GB RAM, 50 GB NVMe$7.20/mo$43.20 for 6 months
A2-4team workflows with larger payloads2 vCPU, 4 GB RAM, 100 GB NVMe$14.40/mo$43.20 for 3 months
A4-8heavy file processing or many parallel runs4 vCPU, 8 GB RAM, 180 GB NVMe$28.80/mo$86.40 for 3 months

Questions about n8n workflow automation

Is n8n free to self-host?

The community edition is source-available under the Sustainable Use License and can be self-hosted for internal business use. Some team features need a paid license key.

Do I need PostgreSQL, or is SQLite enough?

SQLite is the default and fine for a single user. PostgreSQL copes better with many executions and is easier to back up while running.

Why does my webhook URL say localhost?

Set WEBHOOK_URL to the public HTTPS address and recreate the container.

Can n8n run code?

Yes. The Code node runs JavaScript, and Python in recent versions through task runners. Treat workflow editors as trusted users for that reason.

How do I stop old executions filling the disk?

Execution pruning is on by default; adjust EXECUTIONS_DATA_MAX_AGE (hours) and EXECUTIONS_DATA_PRUNE to keep less history.