---
title: "Self-host a headless CMS: the parts and a working setup · CloudSat"
description: "Run a headless CMS on your own server: content API, previews, webhooks and caching, Strapi, Directus or Payload, plus Directus on PostgreSQL with HTTPS."
url: https://cloudsat.io/learn/self-host-a-headless-cms
updated: 2026-11-18T12:00:00Z
source: CloudSat (https://cloudsat.io/). Prices in USD.
---

[Self-hosting](https://cloudsat.io/learn/topic/self-hosting)

# Self-host a headless CMS: the parts and a working setup

Run a headless CMS on your own server: content API, previews, webhooks and caching, Strapi, Directus or Payload, plus Directus on PostgreSQL with HTTPS.

CloudSat team November 18, 2026 7 min read

A headless CMS keeps content and presentation apart. Editors work in an admin app, content leaves through an API, and a separate front end that you build turns it into pages, app screens or anything else. Self-hosting one means running more pieces than a classic CMS: the CMS, its database, usually a cache, the front end, and the glue that rebuilds the site when someone presses publish. This guide covers what each piece does, the candidates worth running yourself, and a working setup with Directus, PostgreSQL and HTTPS.

## Headless, traditional or flat-file

|  | Traditional CMS | Headless CMS | Flat-file CMS |
| --- | --- | --- | --- |
| Who renders pages | The CMS, through its theme | Your front end, built or server-rendered | The CMS, from files |
| Where content lives | Database | Database | Files on disk |
| Who builds the site | Theme and plugin setup | Front-end developers | Template work |
| Fits best | One website | One content source, several channels | Small sites with few edits |
| Pieces to run | App and database | CMS, database, front end, build hook | One app, no database |

If the site is one website edited by a few people, a traditional CMS is less work; our guide to [choosing an open-source CMS](https://cloudsat.io/learn/choose-an-open-source-cms) covers that route, and [flat-file CMS or WordPress](https://cloudsat.io/learn/flat-file-cms-vs-wordpress) covers the no-database option. Headless pays off when the same content feeds a website and an app, when developers want full control of the front end, or when a static front end lets you keep the CMS itself off the public internet.

## The pieces you will run

### The content API

Every headless CMS serves content over REST, GraphQL or both. Give the front end a read-only token scoped to published content, and keep admin tokens out of anything that runs in a browser. If the front end is built ahead of time, the token only exists on the build machine.

### Previews

Drafts are not public, so editors need a preview route in your front end that fetches unpublished content with a separate token. The CMS only opens that URL; you write the route. Strapi includes full-screen Preview on its free plan and keeps Live Preview, the side-by-side view, for paid plans. Directus and Payload also open a preview URL from the editing screen.

### Webhooks

When content changes, the CMS calls a URL. For a static front end, that call starts a rebuild and deploy. For a server-rendered front end, it clears the cached pages that used the content.

### Images

Directus transforms images on request through its assets endpoint, with width, quality and format set in the query string. Strapi generates resized copies when a file is uploaded, and Payload creates the sizes you define in its configuration. Either way, put a cache in front of image URLs.

### Caching

A static front end is the cheapest cache of all: the public site is plain files, and the CMS only answers the build. For live API traffic, enable the CMS's own cache (Directus can use Redis) and cache responses at the reverse proxy or a CDN.

## Candidates you can run yourself

|  | License | Built on | Databases |
| --- | --- | --- | --- |
| Strapi 5 | MIT Community Edition; code in `ee/` directories under a commercial license | Node.js | PostgreSQL 14+, MySQL 8.0+, MariaDB 10.3+, SQLite |
| Directus | Monospace Sustainable Core License | Node.js | Your own SQL database, PostgreSQL and MySQL among them |
| Payload 3 | MIT | TypeScript, inside a Next.js app | MongoDB, PostgreSQL, SQLite |

- **Strapi** defines content types in its admin panel and stores them as files in your project, so the schema travels with your code. MongoDB is not supported.
- **Directus** puts an API and an admin app on top of a SQL database, including one that already exists. Its license allows internal use and client work, forbids offering it as a competing commercial product, and turns each version into GPL-3.0 four years after its release.
- **Payload** is configured in TypeScript and runs inside your Next.js application. Payload joined Figma in June 2025, keeps the MIT license, and its 4.0 beta adds TanStack support next to Next.js.

The classic systems can also run headless: WordPress has a REST API in core, Ghost serves published posts through its read-only Content API, and Drupal ships JSON:API as a core module. That is a sensible route when editors already know the admin.

## A working setup: Directus, PostgreSQL and HTTPS

This setup runs Directus with PostgreSQL and Redis in Docker Compose on an Ubuntu server, with Caddy in front for HTTPS. Point `cms.example.com` at the server first. Create the project and its secrets:

```bash
sudo mkdir -p /opt/directus && cd /opt/directus
# The Directus image runs as the node user, uid 1000
sudo mkdir -p uploads extensions data/database
sudo chown 1000:1000 uploads extensions
sudo tee .env > /dev/null <<EOF
DIRECTUS_VERSION=replace-with-a-release-tag
DIRECTUS_SECRET=$(openssl rand -hex 32)
DB_PASSWORD=$(openssl rand -hex 16)
ADMIN_PASSWORD=$(openssl rand -base64 18)
EOF
sudo chmod 600 .env
```

Set `DIRECTUS_VERSION` to a release from the Directus changelog: the Directus documentation advises pinning an exact version in production rather than `latest`. Then write `compose.yaml`:

```yaml
services:
  database:
    image: postgres:17
    restart: unless-stopped
    environment:
      POSTGRES_USER: directus
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: directus
    volumes:

      - ./data/database:/var/lib/postgresql/data

    healthcheck:
      test: ["CMD", "pg_isready", "--host=localhost", "--username=directus"]
      interval: 10s
      retries: 5

  cache:
    image: redis:7
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "[ $$(redis-cli ping) = 'PONG' ]"]
      interval: 10s
      retries: 5

  directus:
    image: directus/directus:${DIRECTUS_VERSION}
    restart: unless-stopped
    ports:

      - "127.0.0.1:8055:8055"

    volumes:

      - ./uploads:/directus/uploads
      - ./extensions:/directus/extensions

    depends_on:
      database:
        condition: service_healthy
      cache:
        condition: service_healthy
    environment:
      SECRET: ${DIRECTUS_SECRET}
      PUBLIC_URL: "https://cms.example.com"
      DB_CLIENT: "pg"
      DB_HOST: "database"
      DB_PORT: "5432"
      DB_DATABASE: "directus"
      DB_USER: "directus"
      DB_PASSWORD: ${DB_PASSWORD}
      CACHE_ENABLED: "true"
      CACHE_AUTO_PURGE: "true"
      CACHE_STORE: "redis"
      REDIS: "redis://cache:6379"
      ADMIN_EMAIL: "admin@example.com"
      ADMIN_PASSWORD: ${ADMIN_PASSWORD}
```

Publishing the port on `127.0.0.1` matters: ports that Docker publishes on all addresses bypass a host firewall such as UFW, while a loopback port is reachable only through the proxy. Install Caddy from its official package repository and give it this `/etc/caddy/Caddyfile`, which also routes a rebuild hook you will add next:

```caddyfile
cms.example.com {
    handle /hooks/* {
        reverse_proxy 127.0.0.1:9000
    }
    handle {
        reverse_proxy 127.0.0.1:8055
    }
}
```

Start everything with `sudo docker compose up -d`, reload Caddy, and sign in at `https://cms.example.com` with the admin email and the password stored in `.env`. Caddy obtains the certificate on its own.

On CloudSat, the [Docker one-click app](https://cloudsat.io/apps/deploy-docker) gives you the container runtime ready to use, and a [Cloud VPS](https://cloudsat.io/plans) with 4 GB at $11.58 a month holds the CMS, its database and front-end builds side by side.

## Rebuild a static front end on publish

The `webhook` package (`sudo apt install webhook`) turns an HTTP call into a command. Save this as `/etc/webhook/hooks.json`, with a long random token:

```json
[
  {
    "id": "rebuild-site",
    "execute-command": "/opt/site/rebuild.sh",
    "command-working-directory": "/opt/site",
    "trigger-rule": {
      "match": {
        "type": "value",
        "value": "replace-with-a-long-random-token",
        "parameter": { "source": "header", "name": "X-Rebuild-Token" }
      }
    }
  }
]
```

The script builds the front end and swaps in the result. The lock stops two publishes from running two builds at once:

```bash
#!/bin/sh
set -eu
exec 9>/tmp/site-rebuild.lock
flock 9
cd /opt/site
git pull --ff-only
npm ci
npm run build
rsync -a --delete dist/ /var/www/site/
```

Run the listener as a systemd service bound to loopback, so only Caddy can reach it, under a `deploy` user that owns `/opt/site` and `/var/www/site`:

```ini
[Unit]
Description=Static site rebuild hook
After=network.target

[Service]
User=deploy
ExecStart=/usr/bin/webhook -hooks /etc/webhook/hooks.json -ip 127.0.0.1 -port 9000
Restart=on-failure

[Install]
WantedBy=multi-user.target
```

Finally, make the CMS call `https://cms.example.com/hooks/rebuild-site` with the `X-Rebuild-Token` header. In Directus, that is a Flow triggered by item changes with a request operation; Strapi has webhooks in its settings, and Payload can send the request from an `afterChange` hook.

## Backups and sizing

Back up three things: the database, the uploads directory and the `.env` file. Without the same `SECRET`, existing sessions stop working after a restore.

```bash
cd /opt/directus
sudo docker compose exec -T database pg_dump -U directus -Fc directus > "$HOME/directus-$(date +%F).dump"
sudo tar -czf "$HOME/uploads-$(date +%F).tar.gz" uploads .env
```

Copy both files off the server, and restore them once on a spare server with `pg_restore` to prove they work. For sizing, the CMS, PostgreSQL and Redis start comfortably on 2 GB of memory; front-end builds on the same machine are the peak, so allow 4 GB or build elsewhere.

## FAQ

### Can WordPress serve as my headless CMS?

Yes. Its REST API is in core, and editors keep the admin they know. Plugins that change what visitors see, such as SEO or form plugins, stop working until your front end implements their output.

### Does a static front end protect the CMS?

It reduces exposure: visitors only reach plain files, so you can limit the admin to your own IP addresses or a VPN. The CMS still needs updates like any other application.

### Directus, Strapi or Payload?

Directus fits when you want to own the SQL schema or already have a database. Strapi fits teams that want content types defined in the CMS and shipped with the code. Payload fits teams that already build in Next.js and TypeScript.

**Run it on CloudSat.** Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. [See plans](https://cloudsat.io/plans) or [deploy a server](https://dash.cloudsat.io/console/deploy).

## Keep reading

[All guides in Self-hosting](https://cloudsat.io/learn/topic/self-hosting)

- [How to choose an open-source CMS you can self-host](https://cloudsat.io/learn/choose-an-open-source-cms): Self-hosting How to choose an open-source CMS you can self-host 6 min read
- [Flat-file CMS or WordPress: when to skip the database](https://cloudsat.io/learn/flat-file-cms-vs-wordpress): Self-hosting Flat-file CMS or WordPress: when to skip the database 6 min read
- [Drupal or WordPress: the choice from the server side](https://cloudsat.io/learn/drupal-or-wordpress-on-your-own-server): Self-hosting Drupal or WordPress: the choice from the server side 7 min read
- [Run your own RSS reader: FreshRSS, Miniflux or CommaFeed](https://cloudsat.io/learn/run-your-own-rss-reader): Self-hosting Run your own RSS reader: FreshRSS, Miniflux or CommaFeed 7 min read
