The Andre Neves Newsletter

Share this post
Set up a Nostr Relay server in under 5 minutes
andreneves.xyz

Set up a Nostr Relay server in under 5 minutes

Easiest way to get started running your Nostr Relay

André Neves
Dec 17, 2022
14
15
Share this post
Set up a Nostr Relay server in under 5 minutes
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.

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.

Twitter avatar for @jack
jack @jack
14 BTC deployed to @fiatjaf for #nostr
11:42 PM ∙ Dec 15, 2022
704Likes72Retweets
Twitter avatar for @andreneves
André Neves @andreneves
Given the recent announcements by @jack's funding of @nbd_wtf / @zebedeeio developer @fiatjaf to work & foster the #nostr community, I figured it was time to roll out a beefy production-ready relay Presenting nostr.zebedee.cloud wss://nostr.zebedee.cloud #nostr ⚡️ #Bitcoin
7:23 PM ∙ Dec 16, 2022
247Likes46Retweets

While we are running a beefy production-ready nostr relay on nostr.zebedee.cloud already, I wanted to make a simple guide for newcomers that wish to run a relay server and begin interacting with the network themselves.

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.

You may need to setup a static/reserved IP address in order to map the A record to the subdomain.mydomain.com.

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!


Updates/Edits:

  • Dec 31st: Changed `nostr-ts-relay` to `nostream` new package name, and added better info on docker install issues - [RESOLVED]

  • Dec 19th: Changed from using `snap` to install docker in favor of officially supported method with `apt` and Docker’s own repository - [RESOLVED]

  • Dec 18th: Fixed issue with improper quotations and dashes pasted into the code section of Substack - [RESOLVED]

15
Share this post
Set up a Nostr Relay server in under 5 minutes
andreneves.xyz
15 Comments
Lightning Network+
Dec 18, 2022·edited Dec 18, 2022Liked by André Neves

minor typo:

sudo certbot —nginx -d subdomain.mydomain.com

should be:

sudo certbot --nginx subdomain.mydomain.com

Expand full comment
ReplyCollapse
2 replies by André Neves and others
Yaël Ossowski
Writes An Innocent Abroad
Dec 18, 2022Liked by André Neves

what would you say is the safe amount to dedicate for storage?

Expand full comment
ReplyCollapse
1 reply by André Neves
13 more comments…
TopNewCommunity

No posts

Ready for more?

© 2023 André Neves
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing