部署到任意 VPS

普通 Ubuntu 或 Debian VPS 的通用指南 — 其他所有平台指南的基础,含 systemd、TLS 和防火墙说明。

这是普通 Linux VPS(任何提供商 — Hetzner、Vultr、Linode、Contabo、 你自己的服务器……)的通用指南。其他平台指南(Digital Ocean、AWS、GCP、Azure)都是本指南的 快捷方式,附加提供商特定的防火墙步骤。

1. 安装二进制

install.sh 脚本下载适合你架构(x86_64 / aarch64)的最新发布二进制, 验证其 sha256 校验和并安装到 PATH 上的目录 — 安装本身无需 sudo:

sh
curl -fsSL https://raw.githubusercontent.com/iqbqioza/nostrfy/main/install.sh | sh
nostrfy --version

2. 创建配置

获取模板(无需克隆仓库)并编辑:

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

至少设置:

toml
[relay]
name = "My Relay"
public_url = "wss://relay.example.com"   # 你的公开地址
private_key = "..."                      # 在本地运行 'nostrfy genkey' 并粘贴密钥

[server]
host = "0.0.0.0"                         # 模板中已设置
port = 8080

用以下命令生成密钥:

sh
nostrfy --config /tmp/nostrfy-genkey.toml init && nostrfy --config /tmp/nostrfy-genkey.toml genkey

(或者挂载你自己的配置文件代替模板 — 任何 nostrfy.toml 都可以。)

3. 作为 systemd 服务运行

获取加固的单元(无需克隆仓库)并启动它:

sh
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
sudo systemctl status nostrfy

日志:

sh
journalctl -u nostrfy -f

4. 开放端口并验证

在防火墙(ufw、云防火墙、主机防火墙)中允许 TCP 8080:

sh
sudo ufw allow 8080/tcp

从本地和外部验证:

sh
curl http://localhost:8080/health
curl http://<server-ip>:8080/health        # 从你的笔记本

5. 在前端放置终止 TLS 的代理(用于 wss://)

中继在 8080 上提供普通 WebSocket。要将其暴露为 wss://,请在 443 端口运行终止 TLS 的反向代理。中继遵循 X-Forwarded-Proto,因此无需 特殊配置。

nginx

/etc/nginx/sites-available/relay:

nginx
server {
    listen 443 ssl;
    server_name relay.example.com;

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

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

用 certbot 获取免费证书(sudo certbot --nginx -d relay.example.com)。

Caddy

(自动 TLS,一个文件):

caddy
relay.example.com {
    reverse_proxy 127.0.0.1:8080
}

Blossom 媒体主机也一样

设置 blossom.host = "media.example.com" 时,该主机名也必须到达 同一端口 — 中继在内部拆分主机(类似 server.api_host)。为它添加 第二个 server 块 / 站点:

nginx
server {
    listen 443 ssl;
    server_name media.example.com;

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

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
caddy
media.example.com {
    reverse_proxy 127.0.0.1:8080
}

确保配置中的 relay.public_url 与 wss://relay.example.com 匹配。

6. 备份

停止中继,复制数据目录,重新启动:

sh
sudo systemctl stop nostrfy
sudo tar -czf nostrfy-data-backup.tar.gz /var/lib/nostrfy   # 你的 database.path
sudo systemctl start nostrfy

更新

sh
# 管道安装从不询问确认:使用 --force 覆盖
# 现有二进制(或在终端中运行脚本并回答 y/N)
curl -fsSL https://raw.githubusercontent.com/iqbqioza/nostrfy/main/install.sh | sh -s -- --force
sudo systemctl restart nostrfy