Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# Site modes are selected through COMPOSE_PROFILES and are additive:
# local ghost + db, Ghost published on 127.0.0.1:${GHOST_PORT}
# production ghost + db + caddy (HTTPS ingress)
# no-caddy ghost + db, a production site behind the operator's own proxy
# (nginx, Apache) on 127.0.0.1:${GHOST_PORT}
# Optional, per-site profiles: analytics, activitypub, and for local sites
# mailpit, and `supervisor`, which runs Ghost updates asked for in Ghost Admin
# (docs/upgrade-supervisor.md).
Expand All @@ -33,13 +35,13 @@ services:
# Do not alter this without updating the Tinybird Sync container as well
image: ${GHOST_IMAGE_REF:-${GHOST_IMAGE:-ghost}:${GHOST_VERSION:-6-next-alpine}}
restart: ${RESTART_POLICY:-unless-stopped}
profiles: [local, production]
profiles: [local, production, no-caddy]
labels:
<<: *site-labels
org.ghost.docker.lifecycle: long-running
logging: *default-logging
# Loopback only: production ingress is Caddy, and a bring-your-own proxy
# connects over the host loopback interface.
# Loopback only: production ingress is Caddy, or with the `no-caddy`
# profile, the operator's own proxy, over the host loopback interface.
ports:
- "127.0.0.1:${GHOST_PORT:-2368}:2368"
# Application configuration only. Never `.env`.
Expand Down Expand Up @@ -112,7 +114,7 @@ services:
db:
image: mysql:8.0.44@sha256:f37951fc3753a6a22d6c7bf6978c5e5fefcf6f31814d98c582524f98eae52b21
restart: ${RESTART_POLICY:-unless-stopped}
profiles: [local, production]
profiles: [local, production, no-caddy]
labels:
<<: *site-labels
org.ghost.docker.lifecycle: long-running
Expand Down
121 changes: 100 additions & 21 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ value in either file may be a credential.

## Site modes and profiles

Site mode is selected through `COMPOSE_PROFILES`, and exactly one of `local`
or `production` must be present:
Site mode is selected through `COMPOSE_PROFILES`, and exactly one of `local`,
`production` or `no-caddy` must be present:

| Profile | Services | Ingress |
| --- | --- | --- |
| `local` | `ghost`, `db` | Ghost on `127.0.0.1:${GHOST_PORT}` |
| `production` | `ghost`, `db`, `caddy` | Caddy on `${HTTP_PORT}` / `${HTTPS_PORT}` |
| Profile | Services | Ingress | `SITE_MODE` |
| --- | --- | --- | --- |
| `local` | `ghost`, `db` | Ghost on `127.0.0.1:${GHOST_PORT}` | `local` |
| `production` | `ghost`, `db`, `caddy` | Caddy on `${HTTP_PORT}` / `${HTTPS_PORT}` | `production` |
| `no-caddy` | `ghost`, `db` | [Your own proxy](#your-own-proxy), to Ghost on `127.0.0.1:${GHOST_PORT}` | `production` |

A `no-caddy` site is a production site in every other way: backup, restore,
update, `self-update` and the upgrade supervisor treat it as one.

Optional per-site profiles are added to the same list and are purely additive.
Adding one never changes the site mode:
Expand All @@ -130,10 +134,11 @@ supervisor` writes and `self-update` keeps on the release it installs. Every
site's Ghost mounts the `upgrade` volume read-only, where the supervisor's
socket is; it stays empty without the supervisor.

`mailpit` is for local sites only: validation rejects it beside `production`,
where it would catch the site's real mail. `analytics` and `activitypub` are
for production sites only: validation rejects them beside `local`, because
only Caddy's routes reach their services, and a local site has no Caddy. Selecting the profile only runs
`mailpit` is for local sites only: validation rejects it beside `production`
or `no-caddy`, where it would catch the site's real mail. `analytics` and
`activitypub` need Caddy's routes: validation rejects them beside `local`,
which has no Caddy, and beside `no-caddy`, whose proxy the manager does not
configure. Selecting the profile only runs
Mailpit; Ghost sends to it because `ghost.env` says so (`install --with
mailpit` writes those settings; see [install.md](install.md#optional-services)).

Expand All @@ -145,17 +150,91 @@ ActivityPub and analytics are **per-site**: each site owns its ActivityPub
database, storage and serving URL, and its own Tinybird credentials, workspace
selection and schema deployment.

Ghost is always published on the loopback interface only, in both modes, so it
is never exposed publicly except through Caddy.

Caddy is part of `production` rather than an optional profile, deliberately: a
supported bring-your-own-proxy path would mean validating the operator's
forwarded-header configuration, and getting `X-Forwarded-Proto` wrong yields
incorrect absolute URLs and non-secure cookies — a site that half works. If you
already run nginx or Apache, you can still point it at
`127.0.0.1:${GHOST_PORT}` and edit `compose.yml` to drop the caddy service or
move it off 80/443, but that is an unsupported manual customization and stack
updates may touch `compose.yml`.
Ghost is always published on the loopback interface only, in every mode, so
it is never exposed publicly except through Caddy or your own proxy.

### Your own proxy

If the host already runs nginx or Apache, `install --domain example.com
--no-caddy` installs a production site without Caddy, as Ghost-CLI's
`ghost install --no-setup-nginx --no-setup-ssl` did. `COMPOSE_PROFILES` is
`no-caddy`; no `caddy/` is written, and ports 80 and 443 stay your proxy's.
Your proxy terminates HTTPS, with a certificate it obtains, and passes
requests to Ghost on `127.0.0.1:${GHOST_PORT}` (`./ghost-docker info` shows
the port).

The manager does not configure your proxy, and cannot check it: it runs in a
container, which cannot reach the host's loopback port or ask the host's
proxy. Installation and `check` verify Ghost's own health check, and report
the ingress as yours. Opening the site's URL is the check.

The proxy must send three headers:

| Header | Value | Why |
| --- | --- | --- |
| `Host` | the requested host | Ghost serves the site, and Ghost Admin on an admin domain, by name |
| `X-Forwarded-For` | the client's address | Ghost's logs, rate limits and member sign-in see the visitor, not `127.0.0.1` |
| `X-Forwarded-Proto` | `https` | Ghost's `URL` is `https://`, and Ghost redirects a request it believes is plain HTTP to HTTPS |

**A missing or wrong `X-Forwarded-Proto` breaks the site.** Ghost takes
every request for plain HTTP and redirects it to HTTPS, which the proxy
passes back as plain HTTP again: a redirect loop. Where a request does get
through, Ghost treats the connection as insecure, which breaks its secure
session and member cookies: sign-in to Ghost Admin and member sign-in fail.

For nginx, in place of Ghost-CLI's server block (with a certificate from
certbot or any other ACME client):

```nginx
server {
listen 80;
listen [::]:80;
server_name example.com;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;

ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

# Ghost accepts image, media and theme uploads larger than nginx's 1 MB default.
client_max_body_size 50m;

location / {
proxy_pass http://127.0.0.1:2368;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Real-IP $remote_addr;
}
}
```

Replace `2368` with the site's `GHOST_PORT`. With `--admin-domain`, add the
same `server` blocks for the admin domain. For Apache, with `mod_proxy`,
`mod_proxy_http` and `mod_headers`, inside the HTTPS `VirtualHost`:

```apache
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto "https"
ProxyPass / http://127.0.0.1:2368/
ProxyPassReverse / http://127.0.0.1:2368/
```

`mod_proxy` adds `X-Forwarded-For` itself.

ActivityPub and analytics are refused on a `no-caddy` site: they are served by
routes Caddy writes (`/.ghost/activitypub/`, `/.well-known/`,
`/.ghost/analytics/`), which your proxy would have to reproduce. To use them,
install with Caddy instead.

On Linux, use Docker Engine 28 or later: older engines let other machines on
the local network reach ports published on `127.0.0.1`, and so reach Ghost
around your proxy ([Ports](install.md#ports-and-your-existing-proxy)).

## Lifecycle

Expand Down
76 changes: 59 additions & 17 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ clone](#updating-a-clone)) rather than `self-update`.

```text
ghost-docker install [--local | --domain example.com [--admin-domain admin.example.com]
[--email ops@example.com]]
[--email ops@example.com | --no-caddy]]
[--name NAME] [--port 2368] [--version 6.61.0] [--with activitypub,mailpit,supervisor]
[--channel stable|beta | --release vX.Y.Z] [--no-prompt] [--no-start]
ghost-docker install --import BUNDLE [--name NAME] [--port 2368] [--with mailpit] [--no-prompt] [--no-start]
ghost-docker install --import BUNDLE [--domain DOMAIN] [--admin-domain DOMAIN] [--email EMAIL] [--no-start]
ghost-docker install --import BUNDLE [--domain DOMAIN] [--admin-domain DOMAIN] [--email EMAIL | --no-caddy] [--no-start]
```

| Option | Meaning |
Expand All @@ -64,6 +64,7 @@ ghost-docker install --import BUNDLE [--domain DOMAIN] [--admin-domain DOMAIN] [
| `--domain DOMAIN` | A production site: Ghost, MySQL and Caddy with HTTPS on `DOMAIN`. Asked for at a terminal when omitted. |
| `--admin-domain DOMAIN` | A separate Ghost Admin domain. Production only. |
| `--email EMAIL` | The email Caddy registers with Let's Encrypt, which sends expiry notices to it. Production only; optional. |
| `--no-caddy` | A production site behind your own nginx or Apache: no Caddy, and 80 and 443 left to your proxy. See [Your own proxy](#your-own-proxy). |
| `--name NAME` | The site's `COMPOSE_PROJECT_NAME`: lowercase letters, digits and dashes, at most 45 characters. Default: `ghost-example-com` in production, a generated `ghost-local-...` name locally. |
| `--port PORT` | The loopback port Ghost is published on. Default: the first free port at or above 2368. |
| `--version VERSION` | A Ghost version (`6.61.0`) or a full `next` image tag (`6-next-alpine`), pinned to its exact digest. |
Expand All @@ -77,8 +78,10 @@ ghost-docker install --import BUNDLE [--domain DOMAIN] [--admin-domain DOMAIN] [

`install` refuses a directory that already holds a site or data, checks the
host first (as `./ghost-docker doctor` does), generates fresh database
passwords, then starts the site and verifies it through its own ingress. **A
failed installation removes everything it created**, so the same command can
passwords, then starts the site and verifies it: through Caddy, or with
`--no-caddy`, by Ghost's own health check only, since your proxy cannot be
reached from the manager's container. **A failed installation removes
everything it created**, so the same command can
simply be run again. Details: [What installation does](reference.md#what-installation-does).

Exit statuses: `0` installed, `1` failed, `2` a usage error.
Expand All @@ -87,12 +90,12 @@ Exit statuses: `0` installed, `1` failed, `2` a usage error.

| Service | For | What it does |
| --- | --- | --- |
| `--with activitypub` | Production | Runs the site's own ActivityPub service and database, routed through Caddy. |
| `--with activitypub` | Production, with Caddy | Runs the site's own ActivityPub service and database, routed through Caddy. |
| `--with mailpit` | Local | Sends Ghost's mail (invites, password resets, sign-in links) to a [Mailpit](https://mailpit.axllent.org) inbox at `http://127.0.0.1:MAILPIT_PORT` (`./ghost-docker info` shows it). Newsletters go through Mailgun's API, so Mailpit never sees them. |
| `--with supervisor` | Either | Lets Ghost Admin run Ghost updates within the site's major version, each with a checked backup first. Needs Ghost 6.72.0 or later; refused under rootless Docker. See [upgrade-supervisor.md](upgrade-supervisor.md). |

ActivityPub and analytics need Caddy's routes, so a local site cannot select
them; Mailpit would catch a production site's real mail, so a production site
ActivityPub and analytics need Caddy's routes, so a local site, or one
installed `--no-caddy`, cannot select them; Mailpit would catch a production site's real mail, so a production site
cannot select it.

**Analytics** is added after installation, because its Tinybird login is
Expand Down Expand Up @@ -167,7 +170,8 @@ A production site's bundle is installed as a production site, as
sign-in code to confirm the new device, so mail has to work.
- **Nothing is stopped.** If nginx or Apache still holds ports 80 and 443,
Caddy cannot start and the import fails, naming the port. Stopping it is
part of the move below.
part of the move below, unless you [keep nginx](#keeping-nginx) and import
with `--no-caddy`.

### Moving a site to Docker

Expand Down Expand Up @@ -221,14 +225,38 @@ curl -fsSL https://docker.ghost.org/install.sh | bash -s -- install --import ~/m
```

- **Stop nginx yourself.** If it serves other sites too, move those first, or
keep the source (see [Ports](#ports-and-your-existing-proxy)).
[keep nginx](#keeping-nginx).
- DNS already points here; Caddy gets its own certificate when it starts.
- **If the import fails:** `sudo systemctl start nginx`, then `ghost start` in
the source. The bundle is unchanged, so you can retry.
- **Afterwards**, stop both from starting at boot: `sudo systemctl disable
nginx`, and disable the source's `ghost_...` service
(`systemctl list-unit-files 'ghost_*'` names it).

#### Keeping nginx

To keep Ghost-CLI's nginx, and its certificate, serving the site, import
without Caddy. nginx keeps ports 80 and 443, and only the source stops:

```bash
cd /var/www/ghost
ghost stop
ghost migrate-export --output ~/my-site-bundle
mkdir ~/my-site && cd ~/my-site
curl -fsSL https://docker.ghost.org/install.sh | bash -s -- install --import ~/my-site-bundle --no-caddy
```

- **Check nginx points at the new site.** Ghost-CLI's server block sends
requests to the source's port, usually 2368, which the stopped source no
longer holds, so the new site is usually given the same one. If the summary
names another, change `proxy_pass` to it, then `sudo nginx -t && sudo
systemctl reload nginx`; until then nginx answers with a 502 error. Ghost-CLI's
block already sends `X-Forwarded-Proto` ([Your own proxy](#your-own-proxy)).
- **If the import fails:** `ghost start` in the source. nginx was never changed.
- **Afterwards**, disable the source's `ghost_...` service at boot
(`systemctl list-unit-files 'ghost_*'` names it). Leave nginx enabled: it
serves the site now.

#### To another host

```bash
Expand Down Expand Up @@ -281,19 +309,33 @@ directory, with `sudo` because MySQL owns `data/mysql`. For the real move, expor
- A port `install` chooses skips ports other containers publish, and on
macOS ports other programs hold too. A busy port you ask for with `--port`
is an error.
- A production site needs 80 and 443. If anything holds them, installation
fails, names the port, and leaves the directory as it was.
- A production site needs 80 and 443 for Caddy. If anything holds them,
installation fails, names the port, and leaves the directory as it was. A
site installed `--no-caddy` does not use them.

**On Linux, use Docker Engine 28 or later.** Ghost (and Mailpit) are published
on `127.0.0.1` only, but older engines let other machines on the local network
reach those ports, and so Ghost around Caddy. `doctor` and `check` warn about
reach those ports, and so Ghost around Caddy or your own proxy. `doctor` and `check` warn about
such an engine. Docker Desktop, OrbStack and rootless Docker are not affected.

To run Ghost behind your own nginx or Apache instead, point it at
`127.0.0.1:${GHOST_PORT}` and drop the `caddy` service from `compose.yml` or
move it off 80/443. That is an unsupported customization, and stack updates
may touch `compose.yml`; see
[configuration.md](configuration.md#site-modes-and-profiles).
### Your own proxy

If nginx or Apache already serves this host, install without Caddy, as
Ghost-CLI's `ghost install --no-setup-nginx --no-setup-ssl` did:

```bash
curl -fsSL https://docker.ghost.org/install.sh | bash -s -- install --domain example.com --no-caddy
```

Ghost is published on `127.0.0.1:PORT`, which the summary names, and your
proxy serves the domain over HTTPS and passes requests there with `Host`,
`X-Forwarded-For` and **`X-Forwarded-Proto: https`**. Without that last
header Ghost redirects every request to HTTPS, in a loop, and treats the
connection as insecure, which breaks its secure cookies. The nginx server block, the Apache directives, and what is
refused (ActivityPub and analytics) are in
[configuration.md](configuration.md#your-own-proxy). The manager does not
configure or check your proxy; `check` verifies Ghost and reports the ingress
as yours.

How ports are detected on each platform: [Ports](reference.md#ports).

Expand Down
Loading
Loading