Install ntfy on VPS — Self-Hosted Push Notification Server

Install ntfy on VPS: Self-Hosted Push Notifications

October 2026 · 8 min read

ntfy (pronounced "notify") is an open-source pub/sub notification service that works over plain HTTP. You can send a push notification with nothing more than a curl command — no SDK, no API key registration, no account required. You can use the public server at ntfy.sh or self-host on your own VPS for complete privacy. It's ideal for sending alerts from cron jobs, backup scripts, deploy pipelines, or server monitoring — delivered straight to your phone via the ntfy app (Android and iOS).

What is ntfy and Why Self-Host?

ntfy uses a topic-based pub/sub model: publishers POST messages to a URL like https://ntfy.example.com/TOPIC, and all subscribers to that topic receive the notification instantly. Key advantages of ntfy:

Self-hosting ensures your topics are fully private — ideal for sensitive server alerts or script output that shouldn't pass through a public server.

System Requirements

ComponentMinimum
RAM128 MB
Disk1 GB (for message cache)
OSUbuntu 20.04+ / Debian 11+
Port80/443 (or custom port)
DomainSubdomain recommended, e.g. notify.example.com

Install ntfy via apt (Ubuntu/Debian)

This is the recommended approach for Ubuntu/Debian — installs a single binary managed by systemd:

# Add the repository
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://archive.heckel.io/apt/pubkey.txt | sudo gpg --dearmor -o /etc/apt/keyrings/archive.heckel.io.gpg

sudo sh -c "echo 'deb [arch=amd64 signed-by=/etc/apt/keyrings/archive.heckel.io.gpg] https://archive.heckel.io/apt debian main' > /etc/apt/sources.list.d/archive.heckel.io.list"

# Install ntfy
sudo apt update
sudo apt install ntfy

# Verify version
ntfy --version

Install ntfy via Docker Compose

For Docker users, this approach is portable and straightforward:

# Create directory structure
mkdir -p /opt/ntfy/{config,cache}
cd /opt/ntfy

# Create docker-compose.yml
cat > docker-compose.yml <<'EOF'
services:
  ntfy:
    image: binwiederhier/ntfy
    container_name: ntfy
    restart: unless-stopped
    command: serve
    environment:
      - TZ=Asia/Bangkok
    volumes:
      - /opt/ntfy/config:/etc/ntfy
      - /opt/ntfy/cache:/var/cache/ntfy
    ports:
      - "127.0.0.1:2586:80"
EOF

docker compose up -d

Configure ntfy (server.yml)

Create the main configuration file for ntfy:

sudo nano /etc/ntfy/server.yml
# /etc/ntfy/server.yml
base-url: "https://notify.example.com"
listen-http: ":80"
cache-file: /var/cache/ntfy/cache.db
cache-duration: "12h"
attachment-cache-dir: /var/cache/ntfy/attachments
attachment-total-size: "5G"
attachment-file-size: "15M"
attachment-expiry-duration: "3h"

# Enable authentication (recommended)
auth-file: /var/lib/ntfy/user.db
auth-default-access: "deny-all"

# Logging
log-level: info
Note: For Docker installations, place this file at /opt/ntfy/config/server.yml and adjust paths to match your volume mounts.

Configure Nginx Reverse Proxy

ntfy requires WebSocket support for real-time notifications. Configure Nginx accordingly:

sudo nano /etc/nginx/sites-available/ntfy
server {
    listen 80;
    server_name notify.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name notify.example.com;

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

    location / {
        proxy_pass http://127.0.0.1:2586;
        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-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # Required for long-polling and WebSocket
        proxy_read_timeout 3600s;
        proxy_send_timeout 3600s;
    }
}
sudo ln -s /etc/nginx/sites-available/ntfy /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

# Obtain SSL certificate
sudo certbot --nginx -d notify.example.com

User Management and Access Control

ntfy has a built-in auth system. Create an admin user and regular users:

# Create admin user (access to all topics)
sudo ntfy user add --role=admin myadmin
# Enter password when prompted

# Create a regular user
sudo ntfy user add monitoring

# Grant publish/subscribe permissions for specific topics
sudo ntfy access monitoring server-alerts rw   # read+write
sudo ntfy access monitoring backups ro          # read-only

# List all ACL entries
sudo ntfy access

Send Notifications with curl

Once ntfy is running, send notifications immediately from the shell:

# Simplest possible send (public topic)
curl -d "Backup completed!" https://notify.example.com/server-alerts

# Send with title, priority, and tags (with auth)
curl \
  -u "monitoring:PASSWORD" \
  -H "Title: Disk Usage Warning" \
  -H "Priority: high" \
  -H "Tags: warning,floppy_disk" \
  -d "Disk usage on VPS01 exceeded 85%" \
  https://notify.example.com/server-alerts

# Send with an action button (opens URL on tap)
curl \
  -u "monitoring:PASSWORD" \
  -H "Title: Deploy Successful" \
  -H "Actions: view, Open Site, https://example.com" \
  -d "Version 2.1.3 deployed successfully" \
  https://notify.example.com/deploys

Using ntfy in Cron Jobs and Scripts

Use ntfy to send alerts when cron jobs or backup scripts finish:

#!/bin/bash
# /opt/scripts/backup-notify.sh

NTFY_URL="https://notify.example.com/server-alerts"
NTFY_AUTH="monitoring:PASSWORD"

notify() {
  curl -s \
    -u "$NTFY_AUTH" \
    -H "Title: $1" \
    -H "Priority: ${3:-default}" \
    -H "Tags: ${4:-white_check_mark}" \
    -d "$2" \
    "$NTFY_URL" > /dev/null
}

# Run backup
rsync -az /var/www/ [email protected]:/backups/www/
STATUS=$?

if [ $STATUS -eq 0 ]; then
  notify "Backup Successful" "rsync backup completed at $(date '+%H:%M')" "default" "white_check_mark"
else
  notify "Backup Failed!" "rsync backup error code: $STATUS" "urgent" "rotating_light"
fi
# Add to crontab
crontab -e

# Run backup at 02:00 every night with notifications
0 2 * * * /opt/scripts/backup-notify.sh
Tip: Priority levels are: min, low, default, high, urgent. The urgent level triggers a loud sound and can break through Do Not Disturb mode on mobile devices.

Receive Notifications on Mobile

Install the ntfy app and subscribe to your topics:

Verify ntfy is Working Correctly

# Check service status (apt install)
sudo systemctl status ntfy

# Check with Docker
docker compose -f /opt/ntfy/docker-compose.yml ps
docker logs ntfy --tail 20

# Test the health endpoint
curl -s https://notify.example.com/health | python3 -m json.tool

# Send a test message
curl -d "Test from VPS" https://notify.example.com/test-topic

# Inspect sent messages (JSON stream)
curl -s "https://notify.example.com/test-topic/json?poll=1" | head -5

# List users
sudo ntfy user list
Tip: The /health endpoint returns {"healthy":true} when ntfy is ready. Monitor this endpoint with Uptime Kuma to get alerted if ntfy itself goes down.

Troubleshooting Common Issues

Error: "upstream connect error or disconnect/reset before headers"

Nginx cannot reach the ntfy backend. Verify ntfy is listening on the expected port and Nginx is proxying to the correct address:

# Check which port ntfy is listening on
ss -tlnp | grep ntfy
# Or for Docker:
docker port ntfy

# Verify Nginx proxy_pass configuration
sudo nginx -T | grep proxy_pass

# Reload after fixing
sudo systemctl reload nginx

Error: "403 Forbidden — Access denied"

This occurs when auth-default-access: deny-all is set but credentials are missing from the curl command, or the user doesn't have permission for the requested topic:

# Check ACL for a specific user
sudo ntfy access monitoring

# Grant access to the required topic
sudo ntfy access monitoring server-alerts rw

# Test with credentials
curl -u "monitoring:PASSWORD" -d "test" https://notify.example.com/server-alerts

WebSocket not working / notifications not real-time

Nginx must pass Upgrade and Connection headers for WebSocket support:

# Check Nginx config
grep -A5 "location /" /etc/nginx/sites-available/ntfy

# These lines must be present:
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection "upgrade";
# proxy_read_timeout 3600s;

sudo nginx -t && sudo systemctl reload nginx

Error: "database is locked" in logs

Multiple ntfy instances are trying to access the same SQLite database simultaneously. Only one process should run:

# Check for multiple ntfy processes
ps aux | grep ntfy

# If multiple found, stop all
sudo systemctl stop ntfy
sudo pkill -f ntfy

# Start one clean instance
sudo systemctl start ntfy
sudo systemctl status ntfy

iOS not receiving notifications

iOS requires APNs, so ntfy must relay through the ntfy.sh upstream server. Add this to your config:

# Add to server.yml for iOS push support
upstream-base-url: "https://ntfy.sh"

# Restart ntfy after changing config
sudo systemctl restart ntfy

Frequently Asked Questions

How does ntfy differ from Gotify?

Both are self-hosted notification servers, but ntfy's key differentiator is its plain-HTTP API — you can send notifications with just curl, no API token needed in the URL. ntfy also offers a Firebase-free Android app, supports multiple subscribers per topic, and has a built-in web UI. Gotify may be preferable if you need stricter token-based authentication or a more traditional server/client model.

How secure are ntfy topics?

On the public ntfy.sh server, simple topic names like alerts are risky since anyone can subscribe. Self-hosting with auth-default-access: deny-all and user passwords makes topics fully private. Using randomly generated topic names adds an additional layer of security through obscurity.

Does ntfy support file attachments?

Yes — files can be sent directly via HTTP PUT requests. Maximum file size is configurable via attachment-file-size, and files are retained for the duration set by attachment-expiry-duration. This is useful for sending log files or screenshots from monitoring scripts alongside alert messages.