部署到 Google Cloud

在 Google Cloud Compute Engine 或 Cloud Run 上部署 nostrfy — 逐步說明,含 systemd、TLS 與縮容至零的注意事項。

選項:Compute Engine(VM,推薦)或 Cloud Run (容器)。

選項 1:Compute Engine(推薦)

  1. 建立 VM:Ubuntu 24.04 LTS(或 Debian),e2-small(2 GB) 起步足夠。選擇離使用者近的區域。
  2. 防火牆規則:允許入站 TCP 8080(以及 443 用於 TLS)。在 Network → Firewall 下,用你指派給 VM 的目標標籤建立規則。
  3. SSH 登入(主控台的 SSH 按鈕即可)並依照通用 VPS 指南操作:
sh
curl -fsSL https://raw.githubusercontent.com/iqbqioza/nostrfy/main/install.sh | sh
sudo mkdir -p /etc/nostrfy
sudo curl -fsSL -o /etc/nostrfy/nostrfy.toml \
  https://raw.githubusercontent.com/iqbqioza/nostrfy/main/deploy/nostrfy.toml
sudo nano /etc/nostrfy/nostrfy.toml                 # 設定 name、public_url、private_key
sudo curl -fsSL -o /etc/systemd/system/nostrfy.service \
  https://raw.githubusercontent.com/iqbqioza/nostrfy/main/deploy/nostrfy.service
sudo systemctl daemon-reload
sudo systemctl enable --now nostrfy
  1. 保留靜態 IP(External IP → Reserve),使 public_url 在 重新啟動後仍然有效。
  2. 驗證:
sh
curl http://<external-ip>:8080/health
  1. 加入 TLS(wss://)用 certbot + nginx(如 VPS 指南)或帶託管憑證的 GCP 負載平衡器。

選項 2:Cloud Run(容器)

Cloud Run 從倉庫的 Dockerfile 建置(它會下載預編譯的發行 二進位檔):

  1. 從 GitHub 倉庫建立服務(或將映像推送到 Artifact Registry)。
  2. 連接埠:將容器連接埠設為 8080。
  3. 配置記憶體:至少 512 MB(LMDB + 非同步執行環境)。
  4. 持久儲存:在 /data 附加 Cloud Run 磁碟區(filestore/gcsfuse) — LMDB 需要檔案系統,因此在 /data 掛載 GCS FUSE 可實現持久化。
  5. TLS:Cloud Run 自動提供 https:// — 設定 relay.public_url = "wss://<service>.a.run.app"(或你的自訂網域)。
Cloud Run 預設縮容至零
對於中繼,設定 min instances = 1 使其永不變冷。烘焙到映像中的 deploy/nostrfy.container.toml 可以透過在 /etc/nostrfy/nostrfy.toml 掛載你自己的 nostrfy.toml 來替換。