Banner

Ghost 6.19.1

2026-11-27

针对 Ghost 6.19.1 版本,生产环境最稳妥且易于维护的方式是 Docker Compose + MySQL。以下是一份可直接落地的部署与运维指南。

一、 前置准备

  • 服务器:Linux(推荐 Ubuntu 22.04/24.04),至少 1GB 内存、10GB 磁盘。
  • 环境:已安装 Docker 与 Docker Compose 插件。
  • 域名:已解析到服务器公网 IP(本地测试可用 http://localhost:2368)。

二、 目录与配置

mkdir -p /opt/ghost && cd /opt/ghost

1. 创建 .env 文件(集中管理敏感信息)

MYSQL_ROOT_PASSWORD=你的Root密码
MYSQL_PASSWORD=你的Ghost数据库密码
SMTP_USER=你的邮箱
SMTP_PASSWORD=你的邮箱授权码

2. 创建 docker-compose.yml

services:
  ghost:
    image: ghost:6.19.1-alpine
    container_name: ghost
    restart: unless-stopped
    ports:
      - "2368:2368"
    volumes:
      - ./content:/var/lib/ghost/content
    environment:
      NODE_ENV: production
      url: https://你的域名.com
      database__client: mysql
      database__connection__host: db
      database__connection__user: ghost
      database__connection__password: ${MYSQL_PASSWORD}
      database__connection__database: ghost
      mail__transport: SMTP
      mail__options__host: smtp.example.com
      mail__options__port: 587
      mail__options__auth__user: ${SMTP_USER}
      mail__options__auth__pass: ${SMTP_PASSWORD}
      mail__from: "你的站点 <noreply@你的域名.com>"
    depends_on:
      db:
        condition: service_healthy

  db:
    image: mysql:8.0
    container_name: ghost-db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ghost
      MYSQL_USER: ghost
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    volumes:
      - ./mysql:/var/lib/mysql
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  ghost-content:

注:若需严格锁定非 alpine 变体,可将镜像改为 ghost:6.19.1。

三、 启动与初始化

docker compose up -d
docker compose logs -f ghost

看到启动成功后,访问 https://你的域名.com/ghost 完成管理员账号创建。

四、 反向代理与 HTTPS

Ghost 容器仅暴露 2368 端口,生产环境需前置 Nginx 或 Caddy 处理 443 端口与 SSL 证书。以 Nginx 为例:

server {
    listen 443 ssl http2;
    server_name 你的域名.com;
    # ssl_certificate 与 ssl_certificate_key 配置略
    location / {
        proxy_pass http://127.0.0.1:2368;
        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;
    }
}

五、 日常运维与备份

  • 版本升级:修改 docker-compose.yml 中的镜像标签(如 6.19.2),执行 docker compose up -d,Ghost 会自动执行数据库迁移。
  • 数据备份:核心数据仅两处,定期打包即可:
  • 日志排查:docker compose logs --tail 200 ghost,或查看 ./content/logs/ 下的文件。

避坑提示

  • url 环境变量必须与实际访问的域名/协议完全一致(含 https:// 且末尾无 /),否则后台静态资源会加载失败或重定向死循环。
  • 会员登录链接与 Newsletter 强依赖 SMTP 配置,部署后建议先发一封测试邮件验证。
5