Setup your own Nostr relay with Docker
This is a quick tutorial to setup your own Nostr relay using nostream.
This is a quick tutorial to setup your own Nostr relay using nostream (https://github.com/Cameri/nostream).
I'm on Ubuntu 22.04 and you need a running Docker installation as well as Nginx Proxy Manager (https://nginxproxymanager.com/) which provides a simple UI to expose your Nostr relay to the public and also takes care of the SSL certificate.
Required software and instructions how to install them:
- Docker: https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository
- Docker Compose: https://docs.docker.com/compose/install/
- Nginx Proxy Manager (NPM): https://nginxproxymanager.com/setup/
With that up and running, let's get started!
Clone the nostream git repository:
git clone https://github.com/Cameri/nostream
cd nostream
Before starting we need to do some basic configuration:
- docker-compose.yml: make sure that all 4 containers (relay, db, cache and migration) are in the same network as your NPM container so they can find each other using hostnames
- settings.sample.json: you can find a mix of publicly accessible information about the relay as well as some more advanced configurations in here, any changes here are optional
Start the relay:
./scripts/start
The first time, this will take a while and then you'll see that the "web-server-adapter is listening to incoming connections".
So now you just need to expose the relay externally and test if everything works as expected.
Firstly, create a DNS entry for a new subdomain with your domain registrar/provider. I use Cloudflare where I create a DNS record (type A) which points to the IP of my server. The subdomain I use is sg.qemura.xyz.
Secondly, let's configure NPM so it forwards the connections to the right service. Let's login to NPM and go to Hosts --> Proxy Hosts, and then click on "Add Proxy Host".
Configure the proxy host as per screenshot below. Please use 'http' as scheme as the proxy is https, but the relay itself isn't. IMPORTANT: Please make sure that NPM is on the same Docker network as the relay otherwise it won't be able to resolve the hostname ("relay"). Also, please make sure to enable "Websockets Support".
And then let's also add the SSL certificate:
As it creates an SSL certificate using Let's Encrypt this will take about a minute or so.
Use Websocketking (https://websocketking.com/) to test if you can connect to your relay, this is how it should look if everything runs as expected:
You have an up and running Nostr relay! Add it as a relay to your preferred Nostr client and start using it.
Please add your relay to https://nostr.watch/.
Any feedback you can find me on Nostr using my pub key: npub1ccw2rmj0sk5dque6qap5l4rqvqk6jdz6h7dqty4q5k2g79ka830q5sxkpt.