回归 Ghost | 在 Fly.io 部署 Ghost 博客,免费

之前访问过我博客的朋友应该知道,我之前一直使用 Ghost 作为驱动程序,并且部署在 Heroku 上,后来转向了 Nobelium 使用 Notion 作为数据库并部署在 Vercel。

由于对 Nobelium 的前端页面有些许看腻了,又重新转回了 Ghost 并继续使用我在 4 年前设计的主题 1ite

这次转回 Ghost 依旧秉承着除域名外不花一分钱的初心,Heroku 是不能用了,这次就选用 Fly.io,其免费套餐支持部署 3 个 shared 256mb VMs,并可使用 3G 的持久存储卷,下面介绍我是如何在 Fly.io 上部署本博客的。

准备工作

第一步当然是注册 Fly.io 账号,注册账号需要绑定一张信用卡以避免滥用。

注册 Fly.io

然后在本机安装 Flyctl 部署工具。

// Windows
iwr https://fly.io/install.ps1 -useb | iex

// Linux
curl -L https://fly.io/install.sh | sh

// macOS
brew install flyctl

登陆账号

flyctl auth login

开始部署

新建文件夹用于存放配置文件

mkdir ghost-flyio
cd ghost-flyio

新建项目,将 YOURAPPNAME 替换为您欲设置的名称,由于 Fly.io 在很多地方均建立有数据中心,这里选择离大陆较近的东京即 nrt

flyctl launch --name YOURAPPNAME --image=ghost:5-alpine --region nrt --no-deploy

创建储存卷,这里 1G 足够我们用了。

flyctl volumes create ghost_data --region nrt --size 1

配合下方配置信息修改您的配置文件 fly.toml,标注了 这里 的地方必须修改到位。

app = "YOURAPPNAME"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  image = "ghost:5-alpine"

[env] // 这里
  url = "https://YOURAPPNAME.fly.dev"
  database__client = "sqlite3"
  database__connection__filename = "content/data/ghost.db"
  NODE_ENV = "development"

[mounts] // 这里
  source="ghost_data"
  destination="/var/lib/ghost/content"

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 2368 // 这里
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

开始部署

flyctl deploy

绑定域名

1/ 若您的域名为顶级域名,则设置 AAAAA 记录到 flyctl ips list 列出的 IP。
2/ 若为子域名,则 CNAMEYOURAPPNAME.fly.dev

然后执行

flyctl certs create YOUR-BLOG-DOMAIN.com

修改 fly.toml[env] - url 的值为您的域名,重新部署即可。

flyctl deploy
2022-05-21  1+ Views Edit  Top
2024 独立世界. Powered by Ghost with theme bent  
Mastodon