This article was originally published by André Neves on https://andreneves.xyz
This is a quickstart guide for those that wish to run a Nostr Relay. There are tens of relay server options and implementations, but to keep things simple for newcomers to the network, I’m using the friendly `nostream` built in TypeScript and packaged as a Docker Compose YML file.
Table of Contents
Nostr Recap
nostr – Notes and Other Stuff Transmitted by Relays
Nostr is the simplest open protocol that is able to create a censorship-resistant global “social” network once and for all. It doesn’t rely on any trusted central server, hence it is resilient; it is based on cryptographic keys and signatures, so it is tamperproof; it does not rely on P2P techniques, therefore it works.
Recently Jack Dorsey checked out the Nostr protocol first released by ZEBEDEE developer fiatjaf and realized that there’s a LOT of promise and value to the protocol design decisions. So much that he deployed ~$250k to foster the Nostr development community.
FWIW: this setup is different than the infrastructure setup for `nostr.zebedee.cloud`.
Let’s get started!
Setup VM
Choose your preferred VM provider – whether you prefer Linode, Digital Ocean, AWS, GCP, Azure, etc. For this quick guide I used the following setup in DigitalOcean:
- Ubuntu 22.10, 8GB memory, 160GB NVME SSDs
I used these specs for this relay, but there are not yet enough benchmarks to suggest exactly which specs to choose.
Once you’re all setup, SSH into that VM and follow the next steps.
CLI Commands
# Update deps
sudo apt update
# Install nodejs, npm, nginx, certbot
sudo apt install nodejs npm nginx certbot python3-certbot-nginx
# Setup Docker GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Setup `apt` Docker repository
echo
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker
sudo chmod a+r /etc/apt/keyrings/docker.gpg
sudo apt update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# Check installation is successful by checking verions
docker --version
npm --version
node --version
# Clone `nostream` repo
git clone https://github.com/Cameri/nostream.git
# Delete the default nginx settings file
rm -rf /etc/nginx/sites-available/default
# Paste in new settings file contents (see heading NGINX SETTINGS below)
sudo nano /etc/nginx/sites-available/default
# Restart nginx
sudo service nginx restart
# Map DNS A record to IP of VM machine (see DNS SETTINGS below)
# Request SSL cert from letsencrypt/certbot
sudo certbot --nginx -d subdomain.mydomain.com
# Open a TMUX session (to be able to detach and maintain process running)
tmux
# Start the relay
npm run docker:compose:start
# To detach from the TMUX session
Ctrl+B + D
# To re-attach to the TMUX session
tmux a
Nginx Settings
Use the contents below as the contents of the `default` nginx setting.
server{
server_name subdomain.domain.com;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8008;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Setup DNS A Record
To map your VM’s IP address to your subdomain.mydomain.com you need to have an A record like below in your domain DNS settings.
Check Relay Websocket Connectivity
In order to check that the relay is setup correctly, head on over to WebSocketKing and test the connection to your subdomain.domain.com.
Conclusion
That’s it! You’re all setup. This nostr server will ingest and relay any and all events broadcast to it. This isn’t necessarily how a production server would want to be run, but this is a good start.
For more information around limits and event types configuration read more at nostream GitHub repository. Also do note that nostream only supports the following NIPs (Nostr Improvement Protocol) at the moment:
Welcome to Nostr!
Join the #nostr Telegram group to join the development community around this project. You may want to add your relay to nostr.watch for discoverability.
Cheers!