Deployment GuideUpdated August 22, 2026

Practical VPS tutorial

How to Install n8n on a VPS

Install n8n on an Ubuntu VPS with Docker Compose, PostgreSQL and HTTPS. Follow the setup, test a webhook and fix common reverse-proxy and runner errors.

Use the included Caddy container if

TCP ports 80 and 443 are available and DNS points your subdomain at this VPS.

Use your existing Nginx or hosting panel if

another HTTPS site already owns those ports and can proxy to http://127.0.0.1:5678.

Docker Compose gives n8n a home on your VPS, with a permanent HTTPS address for webhooks. The important part is keeping workflows and credentials intact after a restart.

How to Install n8n on a VPS — overview

I'd start with one server, PostgreSQL and a reverse proxy. That's the setup below. By the end, you'll have the editor running on your domain and a small workflow that confirms both webhooks and Code nodes work.

What you need before installing n8n

I'd budget 2 vCPU, 4 GB RAM and 40 GB SSD for this small stack, then measure actual usage. Large files, browser automation and concurrent workflows can need much more memory.

2 vCPU, 4 GB RAM, 40 GB SSDstarting budget for this small stack
n8n 2.45.7the example version pinned in this guide
80 and 443TCP ports HTTPS needs

Have these ready:

  1. A supported Ubuntu Server release, such as 24.04 LTS, with sudo access.
  2. Docker Engine and the Compose plugin. Check with sudo docker compose version.
  3. A subdomain such as n8n.example.com, with DNS pointing to the VPS.
  4. TCP ports 80 and 443 available for HTTPS, while keeping your SSH port allowed.
  5. curl and openssl installed on the host.

Already using Nginx or a hosting panel? Use the existing-proxy option in step 3.

The example pins n8n 2.45.7, listed as stable on October 31, 2026. Check the official releases when installing later; pinning a version makes updates easier to track.

How to Install n8n on a VPS — detail

1. Create the n8n folder and generate your secrets

Keep the deployment in /opt/n8n so the configuration is easy to find later:

sudo mkdir -p /opt/n8n
sudo chown "$(id -u):$(id -g)" /opt/n8n
cd /opt/n8n

Create .env with separate secrets for credentials, runners and PostgreSQL. This block refuses to overwrite an existing file:

(
  umask 077
  set -o noclobber
  cat > .env <<EOF
N8N_VERSION=2.45.7
N8N_HOST=n8n.example.com
GENERIC_TIMEZONE=UTC
N8N_ENCRYPTION_KEY=$(openssl rand -hex 32)
N8N_RUNNERS_AUTH_TOKEN=$(openssl rand -hex 32)
POSTGRES_PASSWORD=$(openssl rand -hex 32)
EOF
)

Edit .env with your hostname and timezone, such as Europe/London or Asia/Shanghai. Keep this file out of Git.

Keep the encryption key. Existing credentials depend on it. Include it in backups and don't regenerate it during updates.

2. Save the Docker Compose configuration

Here's what the four services do:

ServiceJob
n8nRuns the editor, triggers and workflow engine.
PostgreSQLStores workflows, credentials and execution records.
RunnersExecutes Code-node tasks outside the main n8n container.
CaddyHandles HTTPS and forwards requests to n8n.

Save the following as /opt/n8n/compose.yml. The database and runner broker have no public port mapping; n8n's host port is bound to localhost.

name: n8n
services:
  postgres:
    image: postgres:18.6-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: n8n
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}
      POSTGRES_DB: n8n
      PGDATA: /var/lib/postgresql/18/docker
    volumes:
      - postgres_data:/var/lib/postgresql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U n8n -d n8n"]
      interval: 10s
      timeout: 5s
      retries: 10
    logging:
      driver: local

  n8n:
    image: docker.n8n.io/n8nio/n8n:${N8N_VERSION:?set N8N_VERSION}
    restart: unless-stopped
    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_HOST: ${N8N_HOST:?set N8N_HOST}
      N8N_PROTOCOL: https
      N8N_PORT: "5678"
      N8N_EDITOR_BASE_URL: https://${N8N_HOST}/
      N8N_WEBHOOK_URL: https://${N8N_HOST}/
      N8N_PROXY_HOPS: "1"
      GENERIC_TIMEZONE: ${GENERIC_TIMEZONE}
      TZ: ${GENERIC_TIMEZONE}
      N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY:?set N8N_ENCRYPTION_KEY}
      N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS: "true"
      N8N_RUNNERS_MODE: external
      N8N_RUNNERS_BROKER_LISTEN_ADDRESS: 0.0.0.0
      N8N_RUNNERS_AUTH_TOKEN: ${N8N_RUNNERS_AUTH_TOKEN:?set N8N_RUNNERS_AUTH_TOKEN}
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - "127.0.0.1:5678:5678"
    volumes:
      - n8n_data:/home/node/.n8n
    logging:
      driver: local

  runners:
    image: n8nio/runners:${N8N_VERSION}
    restart: unless-stopped
    environment:
      N8N_RUNNERS_TASK_BROKER_URI: http://n8n:5679
      N8N_RUNNERS_AUTH_TOKEN: ${N8N_RUNNERS_AUTH_TOKEN}
    depends_on:
      - n8n
    user: "65532:65532"
    read_only: true
    tmpfs:
      - /tmp:uid=65532,gid=65532,mode=1777
    security_opt:
      - no-new-privileges:true
    logging:
      driver: local

  caddy:
    image: caddy:2-alpine
    restart: unless-stopped
    environment:
      N8N_HOST: ${N8N_HOST}
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    depends_on:
      - n8n
    logging:
      driver: local

volumes:
  postgres_data:
  n8n_data:
  caddy_data:
  caddy_config:

A few details matter here:

  1. Match n8n and runner versions. Both use N8N_VERSION, following the external runner guidance.
  2. Keep both data volumes. The database and /home/node/.n8n hold different parts of the instance.
  3. Use the PostgreSQL 18 storage layout shown. It follows the image documentation. An older major's database directory needs a proper migration.

For a shared PostgreSQL server, use a dedicated application role and database instead of the server's administrator account.

3. Connect your domain and enable HTTPS

For the included Caddy container, save this as /opt/n8n/Caddyfile:

{$N8N_HOST} {
    reverse_proxy n8n:5678
}

Caddy uses the hostname from .env and obtains a certificate automatically when DNS and connectivity are correct. It also handles WebSockets and forwarded headers. There's no need to expose port 5678 publicly.

If you already use Nginx or a hosting panel

Remove the caddy service from the Compose file and use your existing HTTPS site to proxy to http://127.0.0.1:5678. Preserve Host, X-Forwarded-Host, X-Forwarded-Proto and X-Forwarded-For, and disable proxy caching for n8n.

That localhost address assumes the proxy runs on the host. A proxy in another container needs a shared Docker network and the upstream n8n:5678 instead.

The Compose example sets N8N_PROXY_HOPS=1 for one reverse proxy. If you put a CDN or another proxy in front, review the real request chain and trusted headers. See n8n's reverse-proxy configuration.

4. Start n8n and create your owner account

From the project folder, validate the file before starting anything:

cd /opt/n8n
sudo docker compose config --quiet

If validation succeeds, pull the images and launch the stack:

sudo docker compose pull
sudo docker compose up -d
sudo docker compose ps

Once PostgreSQL has initialized, check n8n and the logs:

curl --fail http://127.0.0.1:5678/healthz
sudo docker compose logs --tail=50 n8n runners

Open your HTTPS hostname and create the owner account. Restrict initial access with a VPN or proxy rule until it's ready, and confirm the certificate is valid before logging in.

Now check that a workflow actually runs.

5. Test a production webhook and a Code node

Create a new workflow with two connected nodes:

  1. 01Add a Webhook node. Select GET, set its path to vps-check and leave the response mode as immediate for this test.
  2. 02Add a Code node after it. Choose JavaScript and Run Once for All Items, then use the code below.
return [{ json: { ok: true, message: 'n8n is running on the VPS' } }];

Publish the workflow. Copy its Production URL, which should start with your HTTPS hostname and should not contain :5678. From your computer or another machine, call it:

curl --fail https://n8n.example.com/webhook/vps-check

An immediate HTTP response confirms receipt, not successful execution. Open Executions and check that the Code node finished with ok: true. This tests the public route and runner together.

Test URLs work only while their listener is active. Always-on integrations need a published production URL, as the Webhook documentation explains.

If something doesn't work

SymptomFirst thing to check
address already in use for port 80 or 443Another web server owns the port. Use the existing-proxy option instead of running Caddy.
HTTPS opens, but shows 502 Bad GatewayCheck n8n logs and the upstream address. A container's localhost is not the VPS host.
The webhook shows localhost or the wrong hostnameCheck N8N_WEBHOOK_URL, forwarded headers and proxy hops, then recreate the n8n container.
The webhook returns 404Check the HTTP method, exact path and whether you're calling a published production URL or an active test listener.
The Code node waits for a runnerCheck runner logs, matching image versions and the shared authentication token.

Current n8n documentation uses N8N_WEBHOOK_URL; the older WEBHOOK_URL variable is deprecated. After changing .env, run sudo docker compose up -d so Compose applies changed environment values. Restarting the old container alone does not load a new environment.

Before adding workflows you rely on

Back up PostgreSQL, n8n_data, Compose files and .env. Workflow exports alone aren't a full backup. Follow the Docker backup guide for dumps, archives and a restore test.

For updates, back up first, read the release notes and change N8N_VERSION in .env. Then run:

sudo docker compose pull
sudo docker compose up -d
sudo docker compose logs --tail=50 n8n runners

Recheck the webhook and Code node afterward. A database migration can make rollback more involved than restoring the previous image tag. And keep docker compose down -v out of your normal update routine: it removes the data volumes.

FAQ

Can I install n8n on a 2 GB RAM VPS?

For light testing, possibly. I'd budget 4 GB for this PostgreSQL and external-runner stack, then measure actual executions. Workflows processing large files or several concurrent jobs can need considerably more.

Do I need a GPU VPS for n8n AI workflows?

Not when the workflow calls an external model API. The remote provider runs the model. Local inference is a separate workload with its own CPU, RAM or GPU requirements.

Do I need PostgreSQL to self-host n8n?

n8n supports SQLite too. This guide chooses PostgreSQL for a separate database and a clear backup path. Existing SQLite data will not appear in PostgreSQL just because you change the connection settings.

  1. Install Docker Engine and Compose on Ubuntu
  2. Secure SSH and application ports
  3. Back up Docker apps and restore their data

Next step

Keep the deployment moving

Sources and further reading

Commands assume a fresh Ubuntu server. Replace domains, users, database names and provider-specific values before running them. VPS sizing is a practical starting point, not a guarantee: monitor the real workload and resize when CPU, memory, disk or network headroom becomes tight.

Where to run this

Affiliate links: you pay the same price as buying direct.