🚂 How to Deploy Your Own Private Nostr Relay on Railway (I think??)

You Derek and Alex is this how to do it?
🚂 How to Deploy Your Own Private Nostr Relay on Railway (I think??)

🚂 How to Deploy Your Own Private Nostr Relay on Railway (I think??)

By: DJ Valerie B LOVE (Sonnet 4.5 did this not me ;-)

Time Required: 45-90 minutes

Cost: Free trial (then ~$5-8/month)

Skill Level: Beginner-friendly (no coding required!)


📋 What You’ll Need Before Starting

Gather this information and write it down:

Your Admin Pubkey (hex): [YOUR_HEX_PUBKEY_HERE] Your Admin Pubkey (npub): [YOUR_NPUB_HERE] Your Email: [YOUR_EMAIL_HERE] Your Relay Name: [YOUR_RELAY_NAME - e.g., "My Private Relay"]

To find your hex pubkey:


🚂 PART 1: Create Railway Account (5 minutes)

Step 1: Sign Up for Railway

  1. Go to: https://railway.app

  2. Click “Login” (top right)

  3. Click “Login with GitHub”

If you don’t have GitHub:

  • Go to https://github.com first

  • Click “Sign up”

  • Use your email and create a password

  • Verify your email

  • Return to Railway and login with GitHub

  1. Click “Authorize Railway” when GitHub asks

  2. ✅ You’re in! You should see the Railway dashboard


🔀 PART 2: Fork the Relay Code (5 minutes)

Step 2: Get Your Own Copy of the Relay

  1. Open new tab: https://github.com/scsibug/nostr-rs-relay

  2. Click “Fork” button (top right)

  3. Click “Create fork” (green button)

  4. Wait 10 seconds

  5. ✅ You now have: github.com/YOUR-USERNAME/nostr-rs-relay


📝 PART 3: Configure Your Relay (10 minutes)

Step 3: Edit the Config File

  1. In your forked repo, click config.toml

  2. Click the pencil icon ✏️ (Edit this file)

  3. Delete everything in the file

  4. Paste this config (replace the bracketed values):

`[info] relay_url = “wss://YOUR-RELAY-URL-WILL-GO-HERE.up.railway.app” name = “[YOUR_RELAY_NAME]” description = “[YOUR_RELAY_DESCRIPTION]” pubkey = “[YOUR_HEX_PUBKEY]” contact = “[YOUR_NPUB_OR_EMAIL]”

[database] data_directory = “/data”

[network] port = 8080 address = “0.0.0.0”

[limits] messages_per_sec = 100 max_event_bytes = 131072 max_ws_message_bytes = 524288 max_conn = 128

[authorization] pubkey_whitelist = [ “[YOUR_HEX_PUBKEY]” ]

[options] reject_future_seconds = 1800`

  1. Scroll down

  2. Commit message: Configure relay with my settings

  3. Click “Commit changes”

Note: You’ll update the relay_url later once Railway gives you the URL.


Step 4: Update the Dockerfile

  1. In your repo, click Dockerfile

  2. Click pencil ✏️ to edit

  3. Delete everything

  4. Paste this Dockerfile:

`FROM docker.io/library/rust:1-bookworm as builder ARG CARGO_LOG RUN apt-get update && apt-get install -y cmake protobuf-compiler && rm -rf /var/lib/apt/lists/* RUN USER=root cargo install cargo-auditable RUN USER=root cargo new –bin nostr-rs-relay WORKDIR ./nostr-rs-relay COPY ./Cargo.toml ./Cargo.toml COPY ./Cargo.lock ./Cargo.lock RUN cargo auditable build –release –locked RUN rm src/.rs COPY ./src ./src COPY ./proto ./proto COPY ./build.rs ./build.rs RUN rm ./target/release/deps/nostrrelay* RUN cargo auditable build –release –locked

FROM docker.io/library/debian:bookworm-slim ARG APP=/usr/src/app ARG APP_DATA=/usr/src/app/db RUN apt-get update && apt-get install -y ca-certificates tzdata sqlite3 libc6 && rm -rf /var/lib/apt/lists/* EXPOSE 8080 ENV TZ=Etc/UTC APP_USER=appuser RUN groupadd $APP_USER && useradd -g $APP_USER $APP_USER && mkdir -p ${APP} && mkdir -p ${APP_DATA} COPY –from=builder /nostr-rs-relay/target/release/nostr-rs-relay ${APP}/nostr-rs-relay COPY config.toml /config.toml RUN chown -R $APP_USER:$APP_USER ${APP} USER $APP_USER WORKDIR ${APP} ENV RUST_LOG=info,nostr_rs_relay=info ENV APP_DATA=${APP_DATA} CMD ./nostr-rs-relay –db ${APP_DATA} –config /config.toml`

  1. Scroll down

  2. Commit message: Add config file to Docker build

  3. Click “Commit changes”


🚀 PART 4: Deploy to Railway (15 minutes)

Step 5: Create Railway Project

  1. Go back to Railway: https://railway.app

  2. Click “New Project” (purple button)

  3. Click “Deploy from GitHub repo”

  4. Click “Configure GitHub App”

  5. Select “Only select repositories”

  6. Choose nostr-rs-relay from the dropdown

  7. Click “Install & Authorize”

Step 6: Deploy Your Relay

  1. You should see nostr-rs-relay in the list

  2. Click on it

  3. Click “Deploy Now”

  4. Wait 7-10 minutes - Railway is building (Rust takes time!)

  5. Watch for “Deployed” or green checkmark ✅


🌐 PART 5: Generate Your Relay URL (5 minutes)

Step 7: Get Your Public URL

  1. Click on your deployed nostr-rs-relay service

  2. Click “Settings” tab

  3. Scroll to “Networking” section

  4. Click “Generate Domain”

  5. Railway creates a URL like: nostr-rs-relay-production-XXXX.up.railway.app

  6. Copy this URL!


Step 8: Update Config with Your Real URL

  1. Go back to GitHub: github.com/YOUR-USERNAME/nostr-rs-relay

  2. Click config.toml

  3. Click pencil ✏️ to edit

  4. Find line 2:

    relay_url = "wss://YOUR-RELAY-URL-WILL-GO-HERE.up.railway.app"

  5. Replace with your actual Railway URL:⚠️ Don’t forget the wss:// at the beginning!

    relay_url = "wss://nostr-rs-relay-production-XXXX.up.railway.app"

  6. Commit message: Update relay URL with actual domain

  7. Click “Commit changes”

Step 9: Wait for Auto-Redeploy

  • Railway will detect the change

  • Auto-rebuild (2-3 minutes)

  • Should stay “Online” with green dot


🔐 PART 6: Add Environment Variables (5 minutes)

Step 10: Configure Environment

  1. In Railway, click your nostr-rs-relay service

  2. Click “Variables” tab

  3. Click “+ New Variable“

Add these 3 variables one by one:

Variable 1:

Name: NOSTR_CONFIG_DIR Value: /app

Variable 2:

Name: RUST_LOG Value: info,nostr_rs_relay=info

Variable 3:

Name: PORT Value: 8080

  1. After adding all 3, the relay will auto-redeploy (2-3 minutes)

✅ PART 7: Verify It’s Working (5 minutes)

Step 11: Check the Logs

  1. In Railway, click your service

  2. Click “Deployments” tab

  3. Click on the latest ACTIVE deployment (green checkmark)

  4. Click “Deploy Logs” tab

Look for these SUCCESS messages:

✅ Event publishing restricted to 1 pubkey(s) ✅ Listening on: 0.0.0.0:8080 ✅ database pragma/schema initialized to v18, and ready

Make sure you DON’T see:

❌ Error reading config file ❌ WARNING: Default configuration settings will be used


Step 12: Test WebSocket Connection

  1. Go to: https://websocketking.com

  2. Enter your relay URL: wss://nostr-rs-relay-production-XXXX.up.railway.app

  3. Click “Connect”

  4. ✅ Should say: “Connected to wss://…”


🎊 YOU’RE DONE!

What You Have:

✅ Private Nostr relay running on Railway

✅ NIP-42 authentication enabled

✅ Only YOUR pubkey can publish events

✅ Database ready for your app

✅ WebSocket URL ready to use

Your Relay Info:

Relay URL: wss://[YOUR-RAILWAY-DOMAIN].up.railway.app Admin Pubkey: [YOUR_HEX_PUBKEY] Status: Online ✅ Cost: ~$5-8/month


🔧 Maintenance & Troubleshooting

Adding More Allowed Pubkeys:

When you want to add members to your relay:

  1. Go to GitHub → config.toml

  2. Edit the pubkey_whitelist section:

    [authorization] pubkey_whitelist = [ "YOUR_ADMIN_PUBKEY_HEX", "MEMBER_1_PUBKEY_HEX", "MEMBER_2_PUBKEY_HEX" ]

  3. Commit changes

  4. Railway auto-redeploys (2-3 minutes)

Common Issues:

Relay shows “Crashed”:

  • Check Deploy Logs for error messages

  • Most common: config.toml syntax error

  • Fix the error in GitHub, commit, wait for redeploy

“Config file not found” error:

  • Make sure Dockerfile has: COPY config.toml /config.toml

  • Make sure CMD has: -config /config.toml

Can’t connect to relay:

  • Check if Railway service is “Online”

  • Check if domain is generated in Settings → Networking

  • Try regenerating the domain

Relay restarts frequently:

  • Check Railway usage limits (Trial has resource caps)

  • Upgrade to Hobby plan ($5/month) if needed

Viewing Relay Activity:

  • Railway → Your Service → “Logs” tab

  • See real-time connections and events

  • Monitor for errors or issues

Costs:

  • Trial Plan: 5freecredits,then1/month usage-based

    5freecredits,then

  • Hobby Plan: $5/month minimum (recommended for production)

  • Typical usage: $5-8/month for <100 members


🌟 Next Steps:

Now you can:

  1. Connect your Nostr app to this relay

  2. Publish encrypted events (private data)

  3. Create NIP-29 private communities

  4. Build member-only platforms

  5. Control your own data infrastructure!


💜 Share This Guide!

If this helped you, share it with others learning Nostr!

Built with: Railway + nostr-rs-relay + ❤️

Guide by: DJ Valerie B LOVE (@djvalerieblove)

Questions? Find me on Nostr! ⚡


No comments yet.