Methods to Set up a Nostr Relay in Linux

Nostr is an progressive protocol that creates a decentralized social media platform that’s each light-weight and versatile. To make this work, the Nostr community depends on easy node relays to hold encrypted messages in the direction of their supposed recipients. Right here we information you thru the method of making a Nostr Relay node utilizing Nostream on Ubuntu. We additionally present you the way to connect with your new node on each Gossip and Amethyst shoppers.
Why Use Nostream?
Nostream is a nostr relay, written in Typescript. The primary benefit of utilizing nostream is that it provides you management over your social media information. Just like Pleroma, internet hosting your individual Nostr relay node signifies that you personal your platform and information as you broadcast it over the community.
As well as, Nostream helps a completely Dockerized set up. This implies you possibly can simply deploy it on any present server stack.
Putting in Nostream
Acquiring Docker and Docker Compose
Assumption: This text assumes that you’ve a VPS with at the very least 8GB of RAM in addition to a website title with an A and PTR file pointing to your server’s IP tackle. It additionally assumes that you have already got a Nostr account with a working keypair.
To start out, fetch the signing key for the Docker challenge’s binary package deal repository:
curl -fsSL https://obtain.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /and many others/apt/keyrings/docker.gpg sudo chmod a+r /and many others/apt/keyrings/docker.gpg
Create a brand new repository file for Docker inside your “/and many others/apt/sources.listing.d”:
sudo nano /and many others/apt/sources.listing.d/docker.listing
Paste the next block of code inside your new repository file and put it aside:
deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://obtain.docker.com/linux/ubuntu jammy steady
Replace and improve your Ubuntu system by working the next command:
sudo apt replace && sudo apt improve
Set up the Docker binary together with its Docker Compose plugin and dependencies:
sudo apt set up docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-buildx-plugin nginx git nodejs npm
Lastly, add your present person to the Docker system group:
sudo usermod -aG docker ramces
Acquiring and Putting in nostream
Fetch the git repository for nostream and go contained in the repository folder:
git clone https://github.com/Cameri/nostream.git && cd ./nostream
Run the nostream bootstrap script to construct and deploy the nostream server daemon to as a Docker container in your system:
Wait till the nostream Docker container prints the “nostream” brand, then press Ctrl + C.
Open the configuration file on your nostream occasion utilizing your favourite textual content editor:
nano ./.nostr/settings.yaml
Substitute the worth of the relay_url: and title: variable along with your occasion’s area title.

Substitute the worth of the pubkey: variable with the general public key of your major Nostr account.

Change the e-mail tackle on the contact: variable with a working one that you’re presently utilizing.

Open your occasion’s “docker-compose.yml” file:
nano ./docker-compose.yml
Scroll to the “atmosphere:” class, then change the worth of the “SECRET:” atmosphere variable with a random string of characters.

Notice: You may run the next command to generate a random string of characters: cat /dev/urandom | tr -dc 'A-Za-z0-9' | fold -w 64 | head -n 1
Lastly, restart your nostream occasion:
Accessing Nostream Publicly
To have the ability to entry nostream in your area title, we have to create a Nginx reverse proxy to route the visitors to the Docker occasion.
Create a brand new web site configuration file on your nostream occasion:
sudo nano /and many others/nginx/sites-available/nostream
Paste the next block of code inside your new web site configuration file:
server { server_name nostr.myvpsserver.high; location / { proxy_pass http://127.0.0.1:8008; proxy_http_version 1.1; proxy_set_header Improve $http_upgrade; proxy_set_header Connection "improve"; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; } }
Create a symbolic hyperlink on your new web site configuration file inside “/and many others/nginx/sites-enabled/”:
sudo ln -s /and many others/nginx/sites-available/nostream /and many others/nginx/sites-enabled
Check your Nginx’s settings:
If every thing is ok, apply your new settings by restarting your Nginx server daemon:
sudo systemctl restart nginx
Safe Nostream with SSL Certificates
Make sure that the core snap package deal is working in your VPS:
Set up the certbot snap package deal from the Digital Frontier Basis (EFF):
sudo snap set up certbot --classic
Register your certbot set up to the EFF by working the next command:
sudo certbot register --agree-tos -m you@your-email.invalid
Request a brand new SSL certificates on your nostream reverse proxy:
sudo certbot --nginx -d nostr.myvpsserver.high
Check whether or not your new nostream relay is working by opening an internet browser and navigating to its net tackle.

Linking nostream with the Gossip Nostr Consumer
To hyperlink your new nostream relay with Gossip, click on the “Relays” class on this system’s left sidebar.

Click on the Add Relay button below the “Relays” class.

This can convey up a small textbox the place you possibly can write the tackle of your nostream occasion. Present the tackle of your new relay together with its WebSocket “wss://” protocol header.

Click on “Verify”, adopted by “Configure” to arrange your new relay.
Gossip will then load a settings web page the place you possibly can decide how your new relay will behave along with your consumer. To ship and obtain messages out of your occasion, toggle the “Learn” and “Write” switches on the settings web page.
Toggle the “Inbox”, “Outbox” and “Promote” switches in an effort to talk with different relays.

Check whether or not your relay is correctly working by sending a brand new Nostr word.

Linking nostream with the Amethyst Nostr Consumer
Apart from Gossip, you can too hyperlink your new nostream occasion with different Nostr shoppers resembling Amethyst. To do this, click on your person icon on the app’s higher left nook.

Click on the “Relays” choice on the popup sidebar.

Choose the “Add a Relay” textbox, then sort the tackle of your new relay with out its protocol header.

Click on “Add” to use your new nostream occasion to your consumer.
Check whether or not your new occasion is correctly relaying messages by sending a pattern Nostr word.

Internet hosting a Nostr relay is only one manner of taking again management of your digital life. Apart from your individual social media platform, you can too serve a cloud workplace platform utilizing ownCloud in addition to internet hosting your individual video internet hosting web site by way of Peertube.
Picture credit score: Paulina Chmolowska through Unsplash. All alterations and screenshots by Ramces Crimson.