# Ghost — 部署教程（Docker Compose + 反向代理）

> 专注写作和会员订阅的开源博客 / Newsletter 平台（Node.js）。

- 页面: https://deploy.cc/zh/apps/ghost
- 分类: 博客 / CMS / 文档
- 服务器配置: 官方未给出明确最低配置；本站通用建议：2 核 / 2 GB 内存起（非官方数据）
- 端口: 2368 (Web)
- CPU 架构: 镜像提供 amd64 / arm64（按镜像 manifest 核对于 2026-11-14）
- 一键安装: `curl -fsSL https://deploy.cc/i/ghost.sh -o ghost.sh && sudo bash ghost.sh --domain example.com` (sha256 4305913c98bbe077fee371bc2b1bf2a9a5cfe09a1e8a2a6c3d1b40362f88bf4b)
- 官方仓库: https://github.com/TryGhost/Ghost
- 官方文档: https://ghost.org/docs/
- 部署来源: https://github.com/docker-library/docs/blob/master/ghost/README.md
- 核验程度: 已实测启动（HTTP 200）
- 最后核对: 2026-11-13

## docker-compose.yml (/opt/ghost)

```yaml
# Ghost — docker-compose.yml (deploy.cc)
# 官方来源 / Official source: https://github.com/docker-library/docs/blob/master/ghost/README.md
# 核对日期 / Checked: 2026-11-13
# 改动: 示例 root 密码改为 .env 随机值
# 改动: 宿主端口 8080 改为 2368 并只监听 127.0.0.1
# 改动: 命名卷改为绑定挂载
services:
  ghost:
    image: ghost:6-alpine
    restart: always
    ports:
      - "127.0.0.1:2368:2368"
    environment:
      database__client: mysql
      database__connection__host: db
      database__connection__user: root
      database__connection__password: ${DB_PASSWORD:?set DB_PASSWORD in .env}
      database__connection__database: ghost
      url: ${SITE_URL:?set SITE_URL in .env}
    volumes:
      - ./content:/var/lib/ghost/content
    depends_on:
      - db

  db:
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:?set DB_PASSWORD in .env}
    volumes:
      - ./db:/var/lib/mysql
```

## .env

```bash
# Ghost — deploy.cc .env 模板 / template
# __GEN_*__ 由一键脚本替换为随机值；手动部署请自己改掉。
TZ=Asia/Shanghai
# MySQL root 密码（自动生成） / MySQL root password (generated)
DB_PASSWORD=__GEN_PW__
# 站点地址，例如 https://blog.example.com / Site URL, e.g. https://blog.example.com
SITE_URL=__URL__
```

## 注意

- url 必须是访客实际访问的地址（含 https://），否则后台跳转和链接会出错。
- Docker 官方镜像由 Docker 社区维护；Ghost 官方推荐的生产安装方式是 Ghost-CLI，详见官方文档。

## Nginx

```nginx
# Ghost 反向代理 / reverse proxy — generated by deploy.cc
# 把 example.com 换成你的域名，证书路径按实际修改（certbot / acme.sh 签发）。
# Replace example.com and the certificate paths. More options: https://nginx.cc/zh/gen
# 放到 /etc/nginx/conf.d/<name>.conf，然后 nginx -t && systemctl reload nginx

server {
    listen 80;
    listen [::]:80;
    server_name example.com;

    location /.well-known/acme-challenge/ {
        root /var/www/html;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;  # nginx < 1.25.1: 删除此行，改为 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;
    ssl_protocols TLSv1.2 TLSv1.3;

    client_max_body_size 50m;

    location / {
        proxy_pass http://127.0.0.1:2368;
        proxy_http_version 1.1;
        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_read_timeout 300s;
    }
}
```

## Caddy

```caddy
# Ghost — Caddyfile (deploy.cc). Caddy 会自动申请 HTTPS 证书 / automatic HTTPS
example.com {
    reverse_proxy 127.0.0.1:2368
}
```

## 更新

```bash
cd /opt/ghost && docker compose pull && docker compose up -d && docker image prune -f
```

## 备份

```bash
cd /opt/ghost && docker compose stop && tar czf /root/ghost-$(date +%F).tar.gz -C /opt ghost && docker compose start
```

## FAQ

### Ghost 是什么？

专注写作和会员订阅的开源博客 / Newsletter 平台（Node.js）。官方仓库：https://github.com/TryGhost/Ghost

### 部署 Ghost 需要什么配置的服务器？

官方未给出明确最低配置；本站通用建议：2 核 / 2 GB 内存起（非官方数据）

### Ghost 使用哪些端口？

2368 (Web)。Web 端口只监听 127.0.0.1，通过 Nginx 或 Caddy 反向代理对外提供 HTTPS。

### Ghost 能在 ARM（arm64）服务器上运行吗？

可以。本页 compose 用到的镜像（ghost:6-alpine、mysql:8.0）都提供 arm64 版本（按镜像 manifest 核对于 2026-11-14）。

### 怎样一键安装 Ghost？

在 Linux 服务器上以 root 运行：curl -fsSL https://deploy.cc/i/ghost.sh -o ghost.sh && sudo bash ghost.sh --domain example.com。脚本没有 Docker 时会用官方 get.docker.com 安装，把文件写到 /opt/ghost，生成随机密码，然后 docker compose up -d；端口被占用或目录已存在时会停止，不覆盖。

### Ghost 的数据存在哪里？怎么备份？

所有数据和 .env 都在 /opt/ghost 目录（绑定挂载）。备份：cd /opt/ghost && docker compose stop && tar czf /root/ghost-$(date +%F).tar.gz -C /opt ghost && docker compose start

### 怎样更新 Ghost？

cd /opt/ghost && docker compose pull && docker compose up -d && docker image prune -f。大版本升级前先备份并阅读官方更新说明。

### 这里的 docker-compose 和官方示例有什么不同？

来源：https://github.com/docker-library/docs/blob/master/ghost/README.md。改动：示例 root 密码改为 .env 随机值；宿主端口 8080 改为 2368 并只监听 127.0.0.1；命名卷改为绑定挂载。

---
deploy.cc（非官方站点，商标归各自所有者）· v0.2.2
