一款基于 HTTP 的简单 发布-订阅 通知服务的软件——NTFY

与 Gotify 同一天时间里亦安装 ntfy 来做同步测试。

貌似当时就是因为 ntfy 的用法还未吃透的原因,才没能在当时就将其付诸行动写成水文的!

ntfy

NTFY的简介

ntfy(pronounced notify) 是一个基于 HTTP 的简单 “发布-订阅” 通知服务,它允许您通过脚本从任何计算机使用 REST API 将通知发送到您的手机或电脑桌面。

NTFY的安装

一时之间已经无法寻找到当时安装时的那个版本,实在没办法只好引用现前最新的版本做案例吧。

Debian/Ubuntu

截至2025年9月,官方的ntfy.sh Debian/Ubuntu软件库已迁移到archive.ntfy.sh。旧的存储库archive.heckel.io目前仍然可用,但可能很快就会消失。或许会在2026年初的某个时候逐渐退出。

通过 Debian/Ubuntu 存储库安装

存储库指纹:55BA 774A 6F5E E674 31E4 B6B7 CFDB 962D 4F1E C4AF

mkdir -p /etc/apt/keyrings
curl -L -o /etc/apt/keyrings/ntfy.gpg https://archive.ntfy.sh/apt/keyring.gpg
apt install apt-transport-https
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/ntfy.gpg] https://archive.ntfy.sh/apt stable main" \
    | sudo tee /etc/apt/sources.list.d/ntfy.list
apt update
apt install ntfy
systemctl enable ntfy
systemctl start ntfy

架构太多只安装常用的x86_64/amd64的吧,其中armv7/armhf架构改成arch=armhf即可,arm64架构的改成arch=arm64即可。

通过.deb文件手动安装

根据 CPU 架构下载 deb 文件:

# x86_64/amd64
wget https://github.com/binwiederhier/ntfy/releases/download/v2.22.0/ntfy_2.22.0_linux_amd64.deb
# armv6
wget https://github.com/binwiederhier/ntfy/releases/download/v2.22.0/ntfy_2.22.0_linux_armv6.deb
# armv7/armhf
wget https://github.com/binwiederhier/ntfy/releases/download/v2.22.0/ntfy_2.22.0_linux_armv7.deb
# arm64
wget https://github.com/binwiederhier/ntfy/releases/download/v2.22.0/ntfy_2.22.0_linux_arm64.deb

安装:

dpkg -i ntfy_*.deb
systemctl enable ntfy
systemctl start ntfy

Fedora/RHEL/CentOS

根据 CPU 架构安装 RPM 文件:

# x86_64/amd64
rpm -ivh https://github.com/binwiederhier/ntfy/releases/download/v2.22.0/ntfy_2.22.0_linux_amd64.rpm
# armv6
rpm -ivh https://github.com/binwiederhier/ntfy/releases/download/v2.22.0/ntfy_2.22.0_linux_armv6.rpm
# armv7/armhf
rpm -ivh https://github.com/binwiederhier/ntfy/releases/download/v2.22.0/ntfy_2.22.0_linux_armv7.rpm
# arm64
rpm -ivh https://github.com/binwiederhier/ntfy/releases/download/v2.22.0/ntfy_2.22.0_linux_arm64.rpm

安装:

systemctl enable ntfy 
systemctl start ntfy

Arch Linux

ntfy 可以使用AUR 软件包安装,你可以使用一个AUR 助手比如paruyay或其他工具来下载、构建和安装ntfy并使其保持最新。

paru -S ntfysh-bin

或者运行以下命令手动安装 ntfy :

curl https://aur.archlinux.org/cgit/aur.git/snapshot/ntfysh-bin.tar.gz | tar xzv
cd ntfysh-bin
makepkg -si

NixOS / Nix

ntfy 在 nixpkgs 中作为ntfy-sh打包,可以通过将包名添加到配置文件并调用nixos-rebuild来安装。或者可以使用以下命令在当前用户环境中安装 ntfy:

nix-env -iA ntfy-sh

FreeBSD

ntfy 被移植到 FreeBSD 并通过端口集合作为sysutils/go-ntfy可用,通过pkg安装:

pkg install go-ntfy

macOS

ntfy CLI(仅限ntfy publishntfy subscribe)也支持 macOS。要安装,请下载 tar 包,解压后将其放置在 PATH 中的某个位置(例如:/usr/local/bin/ntfy)。

如果以root用户运行,ntfy 会在/etc/ntfy/client.yml查找其配置。对于其他所有用户,它会在~/Library/Application Support/ntfy/client.yml查找(tar 包中包含示例)。

curl -L https://github.com/binwiederhier/ntfy/releases/download/v2.22.0/ntfy_2.22.0_darwin_all.tar.gz > ntfy_2.22.0_darwin_all.tar.gz
tar zxvf ntfy_2.22.0_darwin_all.tar.gz
sudo cp -a ntfy_2.22.0_darwin_all/ntfy /usr/local/bin/ntfy
mkdir ~/Library/Application\ Support/ntfy 
cp ntfy_2.22.0_darwin_all/client/client.yml ~/Library/Application\ Support/ntfy/client.yml
ntfy --help

在 macOS 上仅支持 ntfy CLI。目前不支持 ntfy 服务器,但你也可以为开发目的构建和运行它。详情请查看构建说明。

Homebrew

要通过 Homebrew(适用于 Linux 和 macOS)安装 ntfy CLI(仅限ntfy publishntfy subscribe),只需运行:

brew install ntfy

Windows

ntfy 服务器和 CLI 在 Windows 上完全受支持。您可以直接运行 ntfy 服务器,也可以作为 Windows 服务运行。要安装,您可以选择:

  • 下载最新的 ZIP 文件,解压后将ntfy.exe二进制文件放置在您的%Path%中的某个位置。
  • 或者通过 Scoop 主仓库安装 ntfy,命令为scoop install ntfy

安装完成后,您可以像这样运行 ntfy CLI 命令:

ntfy.exe -h

Windows 上的默认配置文件位置是服务器的%ProgramData%ntfyserver.yml(例如:C:ProgramDatantfyserver.yml),客户端为%AppData%ntfyclient.yml。你可能需要手动创建目录和配置文件。

要将 ntfy 服务器安装为 Windows 服务,可以使用内置的 sc 命令。例如,在提升权限的命令提示符中运行此命令(根据实际情况调整ntfy.exe的路径):

sc create ntfy binPath="C:\path\to\ntfy.exe serve" start=auto
sc start ntfy

Docker

ntfy 镜像使用起来应该非常简单,可用于amd64armv6armv7arm64

服务器在 80 端口上公开其 Web 界面和 API,因此你需要在 Docker 中暴露该端口。要使用持久消息缓存,你还需要将一个卷映射到/var/cache/ntfy。要更改其他设置,你应该映射/etc/ntfy就可以编辑 /etc/ntfy/server.yml

请注意,Docker 镜像中不包含 /etc/ntfy/server.yml 文件。如果您想使用配置文件,请在镜像外手动创建一个,并将其映射为卷,例如通过 -v /etc/ntfy:/etc/ntfy。您可以将 GitHub 上的 server.yml 文件用作模板。

Docker Run

基本用法(无需缓存或附加配置)
docker run -p 80:80 -it binwiederhier/ntfy serve

使用持久缓存(配置为命令行参数)
docker run \
  -v /var/cache/ntfy:/var/cache/ntfy \
  -p 80:80 \
  -it \
  binwiederhier/ntfy \
    serve \
    --cache-file /var/cache/ntfy/cache.db
使用其他配置选项、时区和非root用户

通过/etc/ntfy/server.yml,参见配置以了解详细信息。

docker run \
  -v /etc/ntfy:/etc/ntfy \
  -e TZ=UTC \
  -p 80:80 \
  -u UID:GID \
  -it \
  binwiederhier/ntfy \
  serve

Docker Compose

在非root用户和启用健康检查的情况下使用docker-compose
services:
  ntfy:
    image: binwiederhier/ntfy
    container_name: ntfy
    command:
      - serve
    environment:
      - TZ=UTC    # optional: set desired timezone
    user: UID:GID # optional: replace with your own user/group or uid/gid
    volumes:
      - /var/cache/ntfy:/var/cache/ntfy
      - /etc/ntfy:/etc/ntfy
    ports:
      - 80:80
    healthcheck: # optional: remember to adapt the host:port to your environment
        test: ["CMD-SHELL", "wget -q --tries=1 http://localhost:80/v1/health -O - | grep -Eo '\"healthy\"\\s*:\\s*true' || exit 1"]
        interval: 60s
        timeout: 10s
        retries: 3
        start_period: 40s
    restart: unless-stopped
    init: true # needed, if healthcheck is used. Prevents zombie processes

如果在运行docker版本时使用非root用户,请确保将server.yml、user.db和cache.db文件和附件目录切割到相同的uid/gid。

自定义 Docker 映像

构建一个自定义的Docker映像,该映像可以使用更少的命令行参数运行,而无需单独交付配置文件。

FROM binwiederhier/ntfy
COPY server.yml /etc/ntfy/server.yml
ENTRYPOINT ["ntfy", "serve"]

此映像可以被推到容器注册表并独立发送。运行它时所需要的只是将ntfy的端口映射到主机端口。

Kubernetes

Kubernetes 的设置与 Docker 非常相似,并且只需要一个相当简单的部署或 Pod 定义即可运行。有几种选项可以混合搭配,包括没有缓存文件的部署、带有持久缓存的有状态集,以及独立无人管理的 Pod。

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ntfy
spec:
  selector:
    matchLabels:
      app: ntfy
  template:
    metadata:
      labels:
        app: ntfy
    spec:
      containers:
      - name: ntfy
        image: binwiederhier/ntfy
        args: ["serve"]
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 80
          name: http
        volumeMounts:
        - name: config
          mountPath: "/etc/ntfy"
          readOnly: true
      volumes:
        - name: config
          configMap:
            name: ntfy
---
# Basic service for port 80
apiVersion: v1
kind: Service
metadata:
  name: ntfy
spec:
  selector:
    app: ntfy
  ports:
  - port: 80
    targetPort: 80

StatefulSet

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: ntfy
spec:
  selector:
    matchLabels:
      app: ntfy
  serviceName: ntfy
  template:
    metadata:
      labels:
        app: ntfy
    spec:
      containers:
      - name: ntfy
        image: binwiederhier/ntfy
        args: ["serve", "--cache-file", "/var/cache/ntfy/cache.db"]
        ports:
        - containerPort: 80
          name: http
        volumeMounts:
        - name: config
          mountPath: "/etc/ntfy"
          readOnly: true
        - name: cache
          mountPath: "/var/cache/ntfy"
      volumes:
        - name: config
          configMap:
            name: ntfy
  volumeClaimTemplates:
  - metadata:
      name: cache
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi

Pod

apiVersion: v1
kind: Pod
metadata:
  labels:
    app: ntfy
spec:
  containers:
  - name: ntfy
    image: binwiederhier/ntfy
    args: ["serve"]
    resources:
      limits:
        memory: "128Mi"
        cpu: "500m"
    ports:
    - containerPort: 80
      name: http
    volumeMounts:
    - name: config
      mountPath: "/etc/ntfy"
      readOnly: true
  volumes:
    - name: config
      configMap:
        name: ntfy

配置相对简单(例如:提供了一个最小配置):

ConfigMap

apiVersion: v1
kind: ConfigMap
metadata:
  name: ntfy
data:
  server.yml: |
    # Template: https://github.com/binwiederhier/ntfy/blob/main/server/server.yml
    base-url: https://ntfy.sh

from-file

kubectl create configmap ntfy --from-file=server.yml 

Kustomize

ntfy 可以使用 Kustomize 部署在 Kubernetes 集群中,Kustomize 是一个使用kustomization.yaml文件自定义 Kubernetes 对象的工具。

  1. 创建新文件夹 – ntfy
  2. 添加下面列出的所有文件
    1. kustomization.yaml:存储部署中使用的所有配置映射和资源
    2. ntfy-deployment.yaml:定义部署类型及其参数
    3. ntfy-pvc.yaml:描述了持久卷将如何创建
    4. ntfy-svc.yaml:将应用程序暴露给内部 Kubernetes 网络
    5. ntfy-ingress.yaml:使用 ingress 控制器将服务暴露到网络外部
    6. server.yaml:简单的服务器配置
  3. kustomization.yaml中将TESTNAMESPACE替换为指定的命名空间
  4. ntfy-ingress.yaml中将ntfy.test替换为所需的 DNS 名称
  5. 将配置应用到当前上下文中的集群集:
    kubectl apply -k /ntfy
    
    

kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ntfy-deployment.yaml # deployment definition
  - ntfy-svc.yaml # service connecting pods to cluster network
  - ntfy-pvc.yaml # pvc used to store cache and attachment
  - ntfy-ingress.yaml # ingress definition
configMapGenerator: # will parse config from raw config to configmap,it allows for dynamic reload of application if additional app is deployed ie https://github.com/stakater/Reloader
    - name: server-config
      files: 
        - server.yml
namespace: TESTNAMESPACE # select namespace for whole application 

ntfy-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ntfy-deployment
  labels:
    app: ntfy-deployment
spec:
  revisionHistoryLimit: 1
  replicas: 1
  selector:
    matchLabels:
      app: ntfy-pod
  template:
    metadata:
      labels:
        app: ntfy-pod
    spec:
      containers:
        - name: ntfy 
          image: binwiederhier/ntfy:v1.28.0 # set deployed version
          args: ["serve"]
          env:  #example of adjustments made in environmental variables
            - name: TZ # set timezone
              value: XXXXXXX
            - name: NTFY_DEBUG # enable/disable debug
              value: "false"
            - name: NTFY_LOG_LEVEL # adjust log level
              value: INFO
            - name: NTFY_BASE_URL # add base url
              value: XXXXXXXXXX 
          ports: 
            - containerPort: 80
              name: http-ntfy
          resources:
            limits:
              memory: 300Mi
              cpu:  200m
            requests:
                  cpu: 150m
                  memory: 150Mi
          volumeMounts:
            - mountPath: /etc/ntfy/server.yml
              subPath: server.yml
              name: config-volume # generated via configMapGenerator from kustomization file
            - mountPath: /var/cache/ntfy
              name: cache-volume # cache volume mounted to persistent volume
      volumes:
        - name: config-volume
          configMap: # uses configmap generator to parse server.yml to configmap
            name: server-config
        - name: cache-volume
          persistentVolumeClaim: # stores /cache/ntfy in defined pv
            claimName: ntfy-pvc

ntfy-pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ntfy-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: local-path # adjust storage if needed
  resources:
    requests:
      storage: 1Gi

ntfy-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: ntfy-svc  
spec:
  type: ClusterIP
  selector:
    app: ntfy-pod
  ports:
    - name: http-ntfy-out
      protocol: TCP
      port: 80
      targetPort:  http-ntfy

ntfy-ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ntfy-ingress
spec:
  rules:
    - host: ntfy.test #select own
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name:  ntfy-svc
                port:
                  number: 80

server.yaml

cache-file: "/var/cache/ntfy/cache.db"
attachment-cache-dir: "/var/cache/ntfy/attachments"

Linux二进制文件

显然基于服务器配置的原因,我也是使用二进制可执行文件部署的。其二进制可执行文件可以在 github 发行版页面获取。

下载并运行

根据具体 CPU 架构下载对应的二进制可执行文件。

x86_64/amd64
wget https://github.com/binwiederhier/ntfy/releases/download/v2.22.0/ntfy_2.22.0_linux_amd64.tar.gz
tar zxvf ntfy_2.22.0_linux_amd64.tar.gz
cp -a ntfy_2.22.0_linux_amd64/ntfy /usr/local/bin/ntfy
mkdir /etc/ntfy && cp ntfy_2.22.0_linux_amd64/{client,server}/*.yml /etc/ntfy
ntfy serve
armv6
wget https://github.com/binwiederhier/ntfy/releases/download/v2.22.0/ntfy_2.22.0_linux_armv6.tar.gz
tar zxvf ntfy_2.22.0_linux_armv6.tar.gz
cp -a ntfy_2.22.0_linux_armv6/ntfy /usr/bin/ntfy
mkdir /etc/ntfy && cp ntfy_2.22.0_linux_armv6/{client,server}/*.yml /etc/ntfy
ntfy serve
armv7/armhf
wget https://github.com/binwiederhier/ntfy/releases/download/v2.22.0/ntfy_2.22.0_linux_armv7.tar.gz
tar zxvf ntfy_2.22.0_linux_armv7.tar.gz
cp -a ntfy_2.22.0_linux_armv7/ntfy /usr/bin/ntfy
mkdir /etc/ntfy && cp ntfy_2.22.0_linux_armv7/{client,server}/*.yml /etc/ntfy
ntfy serve
arm64
wget https://github.com/binwiederhier/ntfy/releases/download/v2.22.0/ntfy_2.22.0_linux_arm64.tar.gz
tar zxvf ntfy_2.22.0_linux_arm64.tar.gz
cp -a ntfy_2.22.0_linux_arm64/ntfy /usr/bin/ntfy
mkdir /etc/ntfy && cp ntfy_2.22.0_linux_arm64/{client,server}/*.yml /etc/ntfy
ntfy serve

安装为服务

只贴出一种类型,其余的可以参考官网的教程。

  1. 编辑/etc/systemd/system/ntfy.service文件:
    [Unit]
    Description=ntfy server
    After=network.target
    
    [Service]
    ExecStart=/usr/local/bin/ntfy serve --no-log-dates
    ExecReload=/bin/kill --signal HUP $MAINPID
    Restart=on-failure
    AmbientCapabilities=CAP_NET_BIND_SERVICE
    LimitNOFILE=10000
    
    [Install]
    WantedBy=multi-user.target
    

    其实压缩包内含ntfy.service有关的文件,但是上面的文件时基于我自己的ntfy.service而贴上的。

  2. 编辑/etc/ntfy/server.yml文件:
    
    base-url: "https://ntfy.cyzwb.com"
    listen-http: "127.0.0.1:22280"
    listen-https: "127.0.0.1:22443"
    
    key-file: /usr/local/openresty/nginx/ssl/ntfy.cyzwb.com.key
    cert-file: /usr/local/openresty/nginx/ssl/ntfy.cyzwb.com.pem
    
    cache-file: "/home/ntfy-data/cache.db"
    cache-duration: "12h"
    # cache-startup-queries:
    cache-batch-size: 0
    cache-batch-timeout: "0ms"
    
    behind-proxy: true
    
    attachment-cache-dir: "/home/ntfy-data/attachments"
    attachment-total-size-limit: "1G"
    attachment-file-size-limit: "1M"
    attachment-expiry-duration: "3h"
    
    log-level: info
    log-level-overrides:
       - "tag=manager -> trace"
       - "visitor_ip=1.2.3.4 -> debug" 
       - "time_taken_ms -> debug"
    log-format: text
    log-file: /var/log/ntfy/ntfy.log
    
    auth-file: "/home/ntfy-data/user.db"
    auth-default-access: "deny-all"
    
    
  3. 启动
    systemctl daemon-reload
    systemctl start ntfy
    

数据库选项

NTFY 使用数据库存储消息(消息缓存)、用户和访问控制,以及网页推送订阅。你可以选择SQLitePostgreSQL作为数据库后端。

SQLite

默认情况下,ntfy 使用 SQLite,每个存储库都有独立的数据库文件。这是最简单的设置,不需要外部依赖:

  • cache-file:消息缓存的数据库文件。
  • auth-file:用于认证和访问控制的数据库文件。如果设置为,则启用认证。
  • web-push-file:用于网页推送订阅的数据库文件。

PostgreSQL(实验性)

详细的参考官网教程。

database-url: "postgres://user:pass@host:5432/ntfy"

NTFY的使用

当时就是想着将这写详细点才没能第一时间乃至第二时间写成水文的,拖延至今日对应的服务器已计划放弃续费,不得不将其付诸行动做出些许记录。

访问控制

默认情况下,ntfy 服务器对所有人开放,意味着每个人都可以读写任何主题。为了限制对自己服务器的访问,你可以选择配置认证和授权。

要设置认证,请配置以下选项:

  • auth-file:用于访问控制(SQLite)的认证数据库文件。如果设置则启用认证和访问控制。
  • auth-default-access:如果在认证数据库中找不到匹配的条目则使用默认权限,默认是:read-write

auth-default-access可选:read-writeread-onlywrite-onlydeny-all。因为是私有使用因此配置为deny-all

配置好后可以使用:

  • 添加或修改用户的命令和配置选项ntfy user
  • 修改访问控制列表和主题模式ntfy access
  • 用于管理用户访问令牌ntfy token

用户与角色

用户可以通过两种不同方式添加到ntfy用户数据库

  • 使用CLI配置
  • 在配置文件中配置

用户通过CLI执行

该命令允许你添加/移除/更改 ntfy 用户数据库中的用户,以及更改密码或角色(或 )。通常只需创建一个管理员用户就能完成所有这些操作:

ntfy user list                     # 显示用户列表 (alias: 'ntfy access')
ntfy user add phil                 # 添加普通用户 phil  
ntfy user add --role=admin phil    # 添加管理员用户 phil
ntfy user del phil                 # 删除用户 phil
ntfy user change-pass phil         # 更改 phil 用户密码 
ntfy user change-role phil admin   # 将用户 phil 设置为管理员
ntfy user change-tier phil pro     # 将Phil的等级改为“专业”
ntfy user hash                     # 生成密码哈希,配合 auth-users 配置选项使用

访问控制列表(ACL)

访问控制列表(ACL)管理非管理员用户的主题访问和匿名访问(所有人/*),每个条目代表用户对特定主题或主题模式的访问权限,条目可以通过两种不同的方式创建:

  • 使用CLI配置
  • 在配置文件中配置

通过CLI进行ACL条目

ACL可以通过以下命令显示或修改:

ntfy access                            # 显示访问控制列表 (alias: 'ntfy user list')
ntfy access USERNAME                   # 显示 USERNAME 的访问控制条目
ntfy access USERNAME TOPIC PERMISSION  # 允许/拒绝 USERNAME 访问 TOPIC

A 是已存在的用户,由(见用户和角色)创建,或匿名用户 或 ,代表访问 API 但无用户名/密码的客户端。

A 要么是特定的主题名称(例如 ,或),要么是匹配任意数量主题的通配符模式(例如 或)。只支持通配角色。它代表从零到任意数量的字符。

A 是以下支持的权限之一:

  1. read-write(别名:rw):允许向指定主题发布消息,以及订阅和阅读消息。
  2. read-only(别名:readro):仅允许订阅和阅读消息,但不允许发布到该主题。
  3. write-only(别名:writewo):只允许发布到该主题,但不允许订阅。
  4. deny(别名:none):不允许发布或订阅某个主题。

示例命令(输入ntfy access --help以了解更多细节):

ntfy access                        # 显示整个访问控制列表
ntfy access phil                   # 显示用户 phil 的访问权限
ntfy access phil mytopic rw        # 允许用户 phil 对 mytopic 具有读写访问权限
ntfy access everyone mytopic rw    # 允许匿名对 mytopic 进行读写访问
ntfy access everyone "up*" write   # 允许匿名只写访问主题“up...”
ntfy access --reset                # 重置整个访问控制列表
ntfy access --reset phil           # 重置用户 phil 的所有访问权限
ntfy access --reset phil mytopic   # 重置用户 phil 和主题 mytopic 的访问权限

访问令牌

除了用户名/密码认证外,ntfy 还通过访问令牌提供认证。访问令牌有助于避免在多个发布/订阅应用之间配置密码。例如,你可能想用专用令牌从备份主机发布,另一个用在家庭自动化系统发布。

你可以用两种不同的方式创建访问令牌:

  • 使用CLI配置
  • 在配置文件中配置

通过CLI获取令牌

可用于管理用户的访问令牌,可以有标签,而且它们可以自动过期(也可能永远不会过期)。每个用户最多可以拥有60个硬编码的令牌。

示例命令(输入ntfy token --help以了解更多细节):

ntfy token list                      # 显示所有用户的令牌列表
ntfy token list phil                 # 显示用户 phil 的令牌列表
ntfy token add phil                  # 为用户 phil 创建永不过期的令牌
ntfy token add --expires=2d phil     # 为用户 phil 创建一个在 2 天后过期的令牌
ntfy token remove phil tk_th2sxr...  # 删除令牌
ntfy token generate                  # 生成随机令牌,可用于 auth-tokens 配置选项

创建访问令牌:

ntfy token add --expires=30d --label="backups" phil
ntfy token list
user phil
- tk_7eevizlsiwf9yi4uxsrs83r4352o0 (backups), expires 15 Mar 23 14:33 EDT, accessed from 0.0.0.0 at 13 Feb 23 13:33 EST

Nginx反向代理

    upstream ntfy {
        # Set the port to the one you are using in gotify
        server 127.0.0.1:22443;
        }

    server {
        listen       443 ssl;
        http2 on;
        server_name  ntfy.cyzwb.com;

        ssl_certificate      /usr/local/openresty/nginx/ssl/ntfy.cyzwb.com.pem;
        ssl_certificate_key  /usr/local/openresty/nginx/ssl/ntfy.cyzwb.com.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
             # We set up the reverse proxy
             proxy_pass         https://ntfy;
             proxy_http_version 1.1;
             
             # Ensuring it can use websockets
             proxy_set_header   Upgrade $http_upgrade;
             proxy_set_header   Connection "upgrade";
             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 http;
             proxy_redirect     http:// $scheme://;
             
             # The proxy must preserve the host because gotify verifies the host with the origin
             # for WebSocket connections
             proxy_set_header   Host $http_host;
             
             
             # These sets the timeout so that the websocket can stay alive
             proxy_connect_timeout   1m;
             proxy_send_timeout      1m;
             proxy_read_timeout      1m;
        }
    }


题外话

运行一年多之后再去使用,发现 ntfy 竟然已经崩溃了,重启服务亦是无效操作。都打算是不是要重装的时候发现点击页面上的 重载 就恢复使用了。

根据文件时间推算安装时的时间:

root@ChiuYut-VM:~# ls -l --time-style=long-iso --time=ctime /usr/local/bin/ntfy 
-rwxr-xr-x 1 1001 127 48417192 2024-11-13 09:46 /usr/local/bin/ntfy
root@ChiuYut-VM:~# ls -l --time-style=long-iso --time=ctime /etc/ntfy/server.yml 
-rw-r--r-- 1 root root 773 2024-11-13 10:25 /etc/ntfy/server.yml

当时的版本:

ntfy 2.11.0 (d11b100), runtime go1.22.2, built at 2024-05-13T20:16:12Z
Copyright (C) 2022 Philipp C. Heckel, licensed under Apache License 2.0 & GPLv2

参考

  • ntfyhttps://ntfy.sh/
  • Getting startedhttps://docs.ntfy.sh/
  • Send push notifications to your phone or desktop using PUT/POSThttps://github.com/binwiederhier/ntfy
  • Official ntfy.sh Debian repositoryhttps://archive.ntfy.sh/apt/
  • Philipp Heckel’s Debian Archivehttps://archive.heckel.io/apt/

ChiuYut

2026年05月10日

发布者

ChiuYut

咦?我是谁?这是什么地方? Ya ha!我是ChiuYut!这里是我的小破站!