Running a strfry Nostr relay after day one: write policy, rate limits and backups
- Decide what your relay is for
- The config sections that matter
- Write policy: the real spam filter
- Rate limits at the proxy
- Backups you can actually restore
- Routine maintenance
- Keep the operator key separate
- Start small, stay boring
Running your own Nostr relay with strfry is one of the more rewarding self-hosting projects in the Bitcoin and Nostr world. The software is fast, the storage is compact, and a small VPS handles far more traffic than most personal or community relays will ever see. The part people underestimate is not the install. It is everything after: who is allowed to write, how you keep spam out, and how you get your data back when the disk dies. This guide covers the day-two basics.
Decide what your relay is for
Before touching any config, write one sentence describing the relay’s job. “A relay for my own notes and my backups.” “A relay for our local meetup group.” “A public relay anyone can write to.” These lead to very different setups.
A personal or group relay should only accept events from a known list of pubkeys. That single decision removes about ninety percent of the spam and moderation work. A fully public relay is a much bigger commitment: you will be storing other people’s content, dealing with abuse reports and paying for the disk. Start small. You can always open up later; closing a relay that people already depend on is far more awkward.
The config sections that matter
strfry reads a single strfry.conf. Most defaults are sensible, but a few sections deserve attention on day one.
db and dbParams. Put the database directory on a disk with room to grow and note the path, because it is what you will back up. The mapsize setting is the maximum size the LMDB database can reach; it is not preallocated, so set it comfortably above what you expect.
relay.info. This block is served as your NIP-11 relay information document. Fill in name, description, the operator pubkey and a contact. Clients and relay directories read it, and a relay with an empty info block looks abandoned. Check the result with a plain HTTP request that sends the header Accept: application/nostr+json to your relay URL.
relay.realIpHeader. If strfry sits behind nginx or Caddy (it usually should, for TLS), set this to the header your proxy sends, for example X-Real-IP. Otherwise every connection appears to come from 127.0.0.1, and any per-IP limit or log becomes useless.
events. Here you can cap maximum event size, the number of tags and the tag value length, and reject events whose timestamps are too far in the future or the past. Tightening the future limit stops clients from posting events dated years ahead that would stick to the top of feeds.
Write policy: the real spam filter
strfry supports a write policy plugin: an external program that receives each incoming event as a line of JSON on standard input and answers accept, reject or shadowReject. This is where you put the rules that match your one-sentence purpose.
For a personal or group relay the plugin can be tiny: accept if the event’s pubkey is on an allowlist file, reject everything else with a short human-readable message. Keep the allowlist in a plain text file, one hex pubkey per line, so adding a member is a one-line change and not a code deploy. Make sure the plugin reloads the file when it changes, or restart it on purpose after each edit.
For a public relay, typical rules include rejecting certain kinds, requiring a minimum proof-of-work, or limiting how many events a single pubkey can write per minute. Shadow-reject is useful against persistent spammers: their client sees success, so they get no feedback to adapt to.
Whatever you write, test it before going live. Pipe a few saved events through the plugin by hand and check the answers. A broken plugin that rejects everything is a quiet failure: your relay looks healthy, it just stopped accepting your own posts.
Rate limits at the proxy
strfry is efficient, but you still do not want a single client opening hundreds of connections or hammering subscriptions. The reverse proxy is the simplest place to cap this. In nginx, limit_conn limits concurrent connections per IP and limit_req limits the request rate for the WebSocket upgrade. Start generous, watch the logs for a week and tighten where you see abuse. Limits that are too strict mostly hurt mobile users behind shared carrier IPs.
Backups you can actually restore
Two kinds of backup make sense.
Logical export. strfry export writes all events as JSON lines to standard output. Redirect it to a dated file, compress it and copy it off the machine. Because the format is just signed Nostr events, it is portable: you can import it into a fresh strfry with strfry import, or replay it to another relay. For a personal relay this is often the only backup you need.
Filesystem copy. Copying the LMDB files while strfry is writing can produce an inconsistent copy. If you want a raw backup, stop the service briefly or use a filesystem snapshot, then copy. Logical exports are usually simpler.
Then do the part almost everyone skips: restore. Once a quarter, start a throwaway strfry on another machine or in a container, import last night’s export and connect a client to it. Check that your own recent notes are there. Write down how long it took and anything you had to look up. That list is your real recovery plan.
Routine maintenance
A short monthly checklist keeps a relay boring, which is what you want:
- Update strfry deliberately. Read the release notes, keep the previous binary or image, export a backup before upgrading, and know how to roll back.
- Watch disk usage. A relay that fills its disk stops accepting writes at the worst moment. Alert well before that.
- Run strfry compact occasionally if you have deleted a lot of data, to reclaim space.
- Review the write-policy logs. A sudden jump in rejections means either a spam wave or a broken rule.
- Re-check the NIP-11 document after config changes.
- Renew and monitor your TLS certificate. Expired certificates silently break most clients.
Keep the operator key separate
Your relay’s info block lists an operator pubkey, but the relay itself never needs your nsec. Do not store a private key on the relay server for convenience. If you sign anything automatically, such as relay announcements, use a dedicated key for that job so a compromised server cannot post as you.
Start small, stay boring
The best relays are not the ones with the cleverest config. They are the ones whose operators know exactly who can write, have a backup they restored last month and get an alert before the disk fills up. Pick a clear purpose, lock down writes to match it and practise the restore.
If you run your own strfry relay and have a trick that saved you from spam or a lost database, share it below. And if this guide helped you, a zap is always appreciated.
Write a comment