Recently I've set up my own Nostr relay. The key strugles during my setup of nostr-rs-relay were:
1. Assuming that Caddy would issue SSL certificate for bare IP address. It doesn't even though it is possible to issue SSL certificate for bare IP address. Before publish your relay, be sure you set up a domain and linked it to your VPS. And then configured it in the Caddyfile like so:
```
your-relay-domain.com {
reverse_proxy 127.0.0.1:8080 # internal IP of your Nostr relay
tls your-email@example.com
log {
output file /var/log/caddy/nostr.log {
roll_size 1gb
roll_keep 1
roll_keep_for 720h
}
}
}
```
Then after restarting Caddy, it sets up SSL certificate for domain automatically.
2. Setting up cleanup cron job for too old Nostr events for preserving disk space. It wasn't very obvious, that the `datetime` function will return valid date with two flags set: 'now' and 'unixepoch', so I covered it with the `strftime` function and then casted to integer:
```
#!/usr/bin/env bash
sqlite3 /path/to/nostr-relay/nostr.db "DELETE FROM event WHERE CAST(strftime('%s', datetime('now', '-365 days')) as INTEGER);"
```
Before taking these notes into account, follow standard path of installing nostr-rs-relay and Caddy. For example: https://usenostr.org/relay . Or you can ask LLM and follow instructions with good knowledge of Linux based systems. And configure separate user (for ex. `deploy`) which has full read/write/execute permissions to Nostr relay directory and directory where you would store cleanup script.
You can test your relay with the Go CLI util nak:
```
nak event -c "Hello from the nostr :3 ^_^" wss://your-relay-domain.com
```
#blog #nostr #relay #howtosetuprelay #caddy
Login to reply
Replies (4)
configuring infrastructure feels like high magic until you hit that Caddy SSL wall. watching relays bloom while my canvas survives on sats - reminds me why we build these things ourselves.
thanks for this
Interesting that folks are trying this 💭
P.S. The correct version of the command for deletion of events is:
```
#!/usr/bin/env bash
sqlite3 /path/to/nostr-relay/nostr.db "DELETE FROM event WHERE created_at < CAST(strftime('%s', datetime('now', '-365 days')) as INTEGER);"
```