Detailed Guide to Deploying a Private Nostr Relay on VPS for Decentralized Social Networking
A detailed guide to deploying a private Nostr Relay on a VPS, enabling participation in decentralized social networks with high security and resistance to censorship.
Image credit: ThomasWolter · Pixabay Content License
Overview of Nostr and Nostr Relay
Nostr (Notes and Other Stuff Transmitted by Relays) is a decentralized social networking protocol that allows users to send messages, images, and content without relying on centralized platforms like Twitter or Facebook. Instead, Nostr operates through relays—servers that store and forward data. Each user can either create their own relay or use someone else’s to participate in the network.
Deploying a private Nostr Relay on a VPS (Virtual Private Server) gives you full control over your data, ensuring high security and protection against censorship. This is ideal for users who value privacy, free speech, and want to contribute to a decentralized social ecosystem.
Prerequisites and Preparation
To deploy a Nostr Relay on a VPS, you need:
- A VPS with at least 2GB RAM, 2 CPU cores, and a Linux OS (Ubuntu 20.04/22.04 or Debian 11/12).
- A static IP address to ensure stable relay operation.
- Root or sudo access to install software.
- SSH access to the VPS.
Deploying Nostr Relay on VPS
We will use nostr-relay, a popular and stable implementation of Nostr Relay. Follow these steps:
1. Install Required Tools
Update the system and install essential tools:
sudo apt update
sudo apt upgrade -y
sudo apt install -y git curl build-essential
2. Install Go (Golang)
Nostr Relay is often written in Golang, so install Go:
sudo apt install -y golang-go
Verify the Go version:
go version
3. Download and Install Nostr Relay
Create a directory for the relay and clone the source code:
mkdir -p ~/nostr-relay && cd ~/nostr-relay
git clone https://github.com/sergiosanchez/nostr-relay.git
cd nostr-relay
4. Configure Nostr Relay
Create a configuration file config.json:
cat > config.json << EOF
{
"listen": "0.0.0.0:8080",
"cors": true,
"max_clients": 1000,
"max_message_length": 10000,
"max_events_per_client": 1000,
"max_relay_events": 10000,
"log_level": "info",
"storage": "memory",
"allow_public_read": true,
"allow_public_write": true
}
EOF
5. Run Nostr Relay
Start the relay with the configured settings:
go run main.go --config config.json
To run in the background, use nohup:
nohup go run main.go --config config.json > /dev/null 2>&1 &
Set Up DNS and Security
To allow others to connect to your relay, set up:
- A domain name (e.g.,
relay.yourdomain.com) pointing to your VPS IP. - SSL/TLS via Let's Encrypt for secure connections:
sudo apt install -y certbot
sudo certbot certonly --standalone -d relay.yourdomain.com
Update the relay configuration to use HTTPS.
Testing and Verification
To verify your relay works:
- Use Nostr apps like Nostr.id or Nsec.io.
- Add your relay to the app’s relay list:
ws://relay.yourdomain.com:8080. - Send a test message to confirm the relay receives and forwards it.
Troubleshooting
- Relay not working: Check logs with
tail -f nohup.outorjournalctl -u nostr-relay. - Cannot connect via DNS: Verify DNS records and wait 5–10 minutes for propagation.
- SSL not working: Run
certbot certificatesto confirm domain verification.
References
- NIPs – Nostr Improvement Proposals
- Nostr Relay GitHub
- Nostr.id – Popular Nostr app
- Nsec.io – Nostr app supporting multiple relays
Deploying a private Nostr Relay on a VPS enables secure, uncensored participation in decentralized social networks. With this guide, you can host your own relay and contribute to a resilient, open Nostr ecosystem.
Related infrastructure & engineering guides: High-RAM Cloud VPS for Self-Hosted LLMs & API Gateways · Comprehensive ERPNext Solution for SMEs: Building a Professional ERP System
High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-4E
10% VAT included
- CPU: 4 vCPU
- RAM: 8 GB
- SSD: 50 GB NVMe
