> ## Documentation Index
> Fetch the complete documentation index at: https://flashrdp.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Self-Host n8n on a VPS with Docker Compose

> Run self-hosted n8n on a Linux VPS with Docker Compose, PostgreSQL and automatic HTTPS from Caddy, then back up the encryption key and data.

**To self-host n8n, install Docker on an Ubuntu or Debian Linux VPS, start n8n, PostgreSQL and Caddy with one Docker Compose file, and point a domain at the server so webhooks work over HTTPS.** n8n is a workflow automation tool; self-hosting keeps your workflows, credentials and execution data on a server you control.

<Tip>Want a server sized for it? [n8n VPS hosting](https://flashrdp.com/ubuntu-vps-for-n8n?utm_source=docs\&utm_medium=guide\&utm_campaign=n8n) ships Ubuntu with full root, from \$11.99/mo.</Tip>

## What you need

* A FlashRDP [Linux VPS](/docs/linux-vps/overview) running **Ubuntu 24.04 LTS** or **Debian 12/13**, with [SSH access as root](/docs/linux-vps/ssh-access).
* A domain or subdomain, such as `n8n.example.com`, with an **A record** pointing to your server's IPv4 address.
* Ports **80** and **443** free. Don't run this next to another web server that already uses them.

## Size the server

n8n's own docs note that it isn't CPU intensive and that memory usually matters more than CPU.

* **One n8n instance:** **BRONZE** (2 vCPU, 4 GB RAM) runs n8n, PostgreSQL and Caddy with room to spare.
* **Queue mode or heavy workflows:** **SILVER** (4 vCPU, 8 GB RAM) or above, for Redis plus n8n workers, or workflows that move large files.

vCPUs are shared, so choose a larger plan for sustained heavy CPU use.

## Install Docker

Install Docker Engine with Docker's convenience script:

```bash theme={null}
curl -fsSL https://get.docker.com | sh
```

<Note>
  This pipes Docker's script into a root shell. To review it first, run `curl -fsSL https://get.docker.com -o get-docker.sh`, read it, then run `sh get-docker.sh`. Docker documents other install methods in its [install guide](https://docs.docker.com/engine/install/).
</Note>

## Create the Compose project

Make a project folder and a `.env` file with your settings:

```bash theme={null}
mkdir -p /opt/n8n && cd /opt/n8n
cat > .env <<'EOF'
N8N_DOMAIN=n8n.example.com
POSTGRES_PASSWORD=change-this-to-a-long-random-password
N8N_ENCRYPTION_KEY=change-this-to-another-long-random-string
TZ=Europe/Paris
EOF
chmod 600 .env
```

Generate random values with `openssl rand -hex 32` and paste them in. Keep a copy of `N8N_ENCRYPTION_KEY` somewhere safe: n8n uses it to encrypt saved credentials, and without it a restored database can't decrypt them.

Create `compose.yaml`:

```yaml theme={null}
services:
  postgres:
    image: postgres:16
    restart: always
    environment:
      - POSTGRES_USER=n8n
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=n8n
    volumes:
      - postgres_data:/var/lib/postgresql/data

  n8n:
    image: n8nio/n8n
    restart: always
    depends_on:
      - postgres
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=n8n
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
      - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
      - N8N_HOST=${N8N_DOMAIN}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - N8N_WEBHOOK_URL=https://${N8N_DOMAIN}/
      - GENERIC_TIMEZONE=${TZ}
      - TZ=${TZ}
      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
    volumes:
      - n8n_data:/home/node/.n8n

  caddy:
    image: caddy:2
    restart: always
    ports:
      - "80:80"
      - "443:443"
    command: caddy reverse-proxy --from ${N8N_DOMAIN} --to n8n:5678
    volumes:
      - caddy_data:/data

volumes:
  postgres_data:
  n8n_data:
  caddy_data:
```

<Info>
  On n8n versions before 2.30.0, the webhook variable is `WEBHOOK_URL` instead of `N8N_WEBHOOK_URL`. Only Caddy publishes ports; n8n and PostgreSQL are reachable only inside the Compose network.
</Info>

## Start n8n

```bash theme={null}
docker compose up -d
docker compose logs -f n8n
```

When the log shows the editor is ready, open `https://n8n.example.com`. Caddy requests a free TLS certificate on first start, which can take a minute. Create the owner account straight away: until you do, anyone who reaches the page can claim it.

## Back up n8n

* **Database:** dump PostgreSQL regularly and copy the file off the server:

```bash theme={null}
cd /opt/n8n && docker compose exec -T postgres pg_dump -U n8n n8n | gzip > n8n-$(date +%F).sql.gz
```

* **Encryption key and settings:** keep your `.env` file and the `n8n_data` volume. The key in `.env` is what decrypts credentials after a restore.
* **Server-level backups:** turn on backups from your server's **Backups** tab in the Billing Portal as a second layer. See [Back up and restore your server](/docs/control-panel/backups).

## Update n8n

```bash theme={null}
cd /opt/n8n && docker compose pull && docker compose up -d
```

Read n8n's release notes before major version updates and back up first.

<Warning>
  n8n is fair-code under the [Sustainable Use License](https://github.com/n8n-io/n8n/blob/master/LICENSE.md): you may self-host it for your own internal business or personal use, but not offer it to others as a hosted automation service. FlashRDP's [Acceptable Use Policy](/docs/terms/use-of-service#restricted-activities) also restricts reselling servers without written agreement.
</Warning>

## Scale with queue mode

For many concurrent executions, n8n's queue mode runs a main process plus workers that take jobs from Redis. Every worker needs the same `N8N_ENCRYPTION_KEY`. Worker concurrency defaults to 10; n8n recommends 5 or higher. Follow n8n's [queue mode docs](https://docs.n8n.io/deploy/host-n8n/configure-n8n/scaling/enable-queue-mode) to add Redis and workers to the Compose file.

## Related Articles

<CardGroup cols={2}>
  <Card horizontal title="Connect via SSH" icon="plug" href="/docs/linux-vps/ssh-access" />

  <Card horizontal title="Persistent Docker Deployments" icon="life-buoy" href="/docs/guides/docker-compose-deployment-recovery" />

  <Card horizontal title="Host Your Own PaaS with Coolify" icon="container" href="/docs/guides/self-hosted-paas-coolify" />

  <Card horizontal title="Back Up and Restore Your Server" icon="archive" href="/docs/control-panel/backups" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.