How to Self-Host Your Own ntfy Push Notification Server

Deploy your own ntfy server on Railway, lock it down with user accounts, and send push notifications to your phone with a single curl command.

If you run scripts, cron jobs, CI pipelines or a home server, you'll want to know when a job fails or finishes. ntfy sends that alert to your phone as a push notification from a single HTTP request, with no SDK to install. This post shows how to deploy your own ntfy server on Railway, make it private, and publish your first notification.

ntfy web app showing push notifications in a topic
Image source: ntfy.sh

What is ntfy?

ntfy (pronounced "notify") is an open-source push notification service. You publish a message to a topic with curl or any HTTP client, and every device subscribed to that topic gets it as a push notification, on Android, iOS, the desktop or the web app. On a server without access control, publishing doesn't need an account or an API key.

Common uses for ntfy push notifications
Common uses for ntfy push notifications

Why Self-Host Instead of Using ntfy.sh?

The public ntfy.sh server is free for light use, and its paid plans add reserved topics and higher limits. On the free tier, any topic is open to anyone who guesses its name, and the server's defaults decide how long messages and attachments are kept, how often you can publish, and how large an attachment can be (15 MB for free users). On your own server, you decide who can publish and subscribe, you set those limits yourself, and your messages stay on infrastructure you run.

Deploy ntfy on Railway

My ntfy template on Railway deploys the official ntfy Docker image with a persistent volume, and it works on the generated up.railway.app domain with no extra setup. To use your own domain, see the last section of this post.

Deploy on Railway

The template sets these environment variables, which you can change in the service settings:

NTFY_BEHIND_PROXY=true
NTFY_CACHE_FILE=/var/lib/ntfy/cache.db
NTFY_AUTH_FILE=/var/lib/ntfy/auth.db
NTFY_ATTACHMENT_CACHE_DIR=/var/lib/ntfy/attachments
NTFY_BASE_URL=https://${{RAILWAY_PUBLIC_DOMAIN}}

The message cache, user database and attachments all live on the volume at /var/lib/ntfy, so they survive restarts and redeploys. If you'd rather run ntfy on a virtual machine, the same Docker image runs on any server, such as a DigitalOcean droplet.

iOS Push Notifications

iOS only delivers instant notifications through Apple's push service, and a self-hosted server can't use it directly. ntfy handles this with an upstream relay: set NTFY_UPSTREAM_BASE_URL=https://ntfy.sh, and your server sends ntfy.sh a poll request containing only the message ID and a hash of the topic URL. The iOS app then fetches the message itself from your server, so the content never passes through ntfy.sh. See the iOS docs for details.

Web Push Notifications

Web Push sends browser notifications even when the ntfy web app isn't open. It needs a VAPID key pair, which ntfy webpush keys generates, plus a database file and a contact email address.

Send Your First Notification

Install the ntfy app on your phone, add your server's URL in its settings, and subscribe to a topic such as backups. Then publish a message to it:

curl -d "Nightly backup finished" https://your-app.up.railway.app/backups

The same request works from a script, a CI job or a webhook handler. Headers add a title, priority, tags or a click action, and the publishing docs list them all.

Lock Down Your Instance

By default, anyone with your server's URL can publish and subscribe. To make it private, add these two variables in the service settings:

NTFY_AUTH_DEFAULT_ACCESS=deny-all
NTFY_ENABLE_LOGIN=true

Then create an admin user inside the running container. Right-click the service in the Railway dashboard, choose Copy SSH Command, run it with the Railway CLI, and add the user:

ntfy user add --role=admin yourname

To publish from scripts without a password, create an access token with ntfy token add yourname and send it as a header:

curl -H "Authorization: Bearer tk_..." -d "Nightly backup finished" https://your-app.up.railway.app/backups

If you can't open a shell, you can define users in the NTFY_AUTH_USERS variable with a bcrypt-hashed password instead. The access control docs cover both options.

Subscribe to Your Instance

Once your server is running, subscribe to topics with any ntfy client:

  • The Android app from Google Play or F-Droid, with your server URL added in its settings.
  • The iOS app from the App Store, with the upstream relay above set up for instant notifications.
  • The web app, at your server's up.railway.app URL.
  • The ntfy CLI, with ntfy subscribe --from-config and your server set in ~/.config/ntfy/client.yml.

Additional Configuration Options

On Railway, you configure ntfy with environment variables. The table lists the ones you're most likely to change, and the config reference has the rest.

Environment Variable What It Does Example Value
NTFY_CACHE_DURATION How long messages are kept for subscribers who connect late 24h, 72h
NTFY_ATTACHMENT_TOTAL_SIZE_LIMIT Maximum total size of all stored attachments 5G
NTFY_ATTACHMENT_FILE_SIZE_LIMIT Maximum size of a single attachment 15M
NTFY_ATTACHMENT_EXPIRY_DURATION How long attachments are kept before deletion 3h
NTFY_GLOBAL_TOPIC_LIMIT Maximum number of topics on the server 5000
NTFY_VISITOR_REQUEST_LIMIT_BURST Requests one IP can make in a burst before rate limiting starts 60
NTFY_VISITOR_MESSAGE_DAILY_LIMIT Messages one IP can publish per day 15000
NTFY_SMTP_SENDER_ADDR SMTP server for sending notifications by email smtp.example.com:587
NTFY_SMTP_SERVER_LISTEN Accept inbound email, so you can publish by sending an email :25
NTFY_UPSTREAM_BASE_URL Relay through ntfy.sh for instant iOS notifications https://ntfy.sh
NTFY_WEB_PUSH_PUBLIC_KEY, NTFY_WEB_PUSH_PRIVATE_KEY, NTFY_WEB_PUSH_FILE, NTFY_WEB_PUSH_EMAIL_ADDRESS Browser push notifications without keeping the web app open VAPID key pair, database path, contact email
NTFY_LOG_LEVEL Logging verbosity info, debug
NTFY_AUTH_USERS Define users in a variable, with bcrypt-hashed passwords See docs

Frequently Asked Questions

Is ntfy free? Yes. The server is open source, and the public ntfy.sh server is free for light use, with paid plans for reserved topics and higher limits. When you self-host, you pay only for the server it runs on.

Does ntfy work on iPhone with a self-hosted server? Yes. Set NTFY_UPSTREAM_BASE_URL=https://ntfy.sh for instant notifications. Only the message ID and a topic hash go to ntfy.sh, and the app fetches the message from your server.

How do I stop strangers from using my ntfy server? Set NTFY_AUTH_DEFAULT_ACCESS=deny-all, create users with ntfy user add, and publish with a username and password or an access token.

Subscribe to alphasec

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe