Run your own Nostr relay

Public relays can disappear, change their policies, or delete old data. A self-hosted relay gives you control over availability, retention, and access. With Blossom included, your encrypted attachments stay on infrastructure you choose as well.

Recommended software

nostrfy runs a relay and Blossom from one binary

nostrfy is a lightweight Nostr relay with an integrated Blossom file server. Both services run in one process on one port, while separate hostnames keep relay and media traffic easy to configure.

Before you start

This setup follows nostrfy's official VPS deployment on a current Debian or Ubuntu server. Review the download script before running it, use a clean VPS, and adapt the example limits and access policy to your needs.

  • A clean Debian or Ubuntu VPS with a public IP address.
  • Two subdomains: one for the relay and one for Blossom media.
  • SSH access and inbound ports 80 and 443 open.
  • Enough disk space for the relay database, encrypted media, and backups.

1. Point both hostnames to the server

Create A or AAAA records for the relay and Blossom endpoint. Replace the example names with your domain and wait until both resolve publicly before Caddy requests their certificates.

DNS records
relay.example.com  A/AAAA  YOUR_SERVER_IP
media.example.com  A/AAAA  YOUR_SERVER_IP

2. Install nostrfy and fetch the configuration

Download the checksum-verifying installer, inspect the exact file you will execute, and install the binary system-wide. Then create an unprivileged service user and fetch the official configuration template: Review the installer source.

Terminal
curl -fsSLo nostrfy-install.sh \
  https://raw.githubusercontent.com/iqbqioza/nostrfy/main/install.sh
less nostrfy-install.sh
chmod +x nostrfy-install.sh
sudo env INSTALL_DIR=/usr/local/bin ./nostrfy-install.sh

sudo useradd --system --create-home --home-dir /var/lib/nostrfy nostrfy
sudo install -d -o nostrfy -g nostrfy -m 0750 /etc/nostrfy
sudo curl -fsSLo /etc/nostrfy/nostrfy.toml \
  https://raw.githubusercontent.com/iqbqioza/nostrfy/main/deploy/nostrfy.toml
sudo chown nostrfy:nostrfy /etc/nostrfy/nostrfy.toml
sudo chmod 600 /etc/nostrfy/nostrfy.toml
sudoedit /etc/nostrfy/nostrfy.toml

3. Configure the relay and Blossom

Edit /etc/nostrfy/nostrfy.toml and merge these values into the downloaded template. The example keeps relay writes and Blossom uploads public; tighten both policies for a private server:

  • Set relay.public_url to the final wss:// address so NIP-42 authentication uses the correct origin.
  • Leave relay.require_auth false for an open relay, or enable it when every client that needs access supports NIP-42.
  • Set blossom.host to the media hostname and choose local or S3-compatible storage with an appropriate upload limit.
  • For a private service, enable the relay and Blossom restrictions and add permitted pubkeys with the nostrfy CLI.
nostrfy.toml
[relay]
name = "My Relay"
public_url = "wss://relay.example.com"
require_auth = false

[server]
host = "0.0.0.0"
port = 8080
trusted_proxies = ["127.0.0.1/32", "::1/128"]

[database]
path = "/var/lib/nostrfy"

[blossom]
host = "media.example.com"
storage = "local"
local_path = "/var/lib/nostrfy/images"
max_upload_bytes = 20971520
restrict_uploads = false

4. Start the service and add automatic HTTPS

Validate the configuration, install nostrfy's hardened systemd unit, and put Caddy in front of the local port. Caddy routes both hostnames to nostrfy and obtains and renews their TLS certificates automatically.

  • Run nostrfy check before starting the service and fix every configuration error.
  • Run nostrfy as the unprivileged nostrfy user rather than as root.
  • Expose ports 80 and 443 publicly, but keep nostrfy's port 8080 behind the proxy.
  • Route both relay.example.com and media.example.com to 127.0.0.1:8080 in Caddy.
  • Confirm that nostrfy and Caddy are active and that certificate issuance succeeds.
/etc/caddy/Caddyfile
relay.example.com, media.example.com {
  reverse_proxy 127.0.0.1:8080
}
Terminal
sudo -u nostrfy /usr/local/bin/nostrfy \
  --config /etc/nostrfy/nostrfy.toml check

sudo curl -fsSLo /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 apt update
sudo apt install -y caddy
sudoedit /etc/caddy/Caddyfile
sudo systemctl reload caddy
sudo systemctl status nostrfy caddy

Check and connect

The first request should return the relay's NIP-11 JSON. The second should return the Blossom server information document, confirming that DNS, HTTPS, host routing, and both services work.

Terminal
curl -H 'Accept: application/nostr+json' \
  https://relay.example.com

curl -sS https://media.example.com/
Relay address
wss://relay.example.com
Blossom address
https://media.example.com

Add the secure WebSocket address in your Nostr client's relay settings and confirm that it connects. Use the Blossom address in clients that support a custom media server.

Keep it healthy

Self-hosting also means maintaining the service. Schedule these three tasks from the start:

  1. Back up /etc/nostrfy/nostrfy.toml and /var/lib/nostrfy, including the database and Blossom files.
  2. Read nostrfy's release notes and current upgrade instructions before replacing the binary.
  3. Monitor disk space, journalctl -u nostrfy, Caddy logs, and certificate renewal.