🚂 How to Deploy Your Own Private Nostr Relay on Railway (I think??)
- 🚂 How to Deploy Your Own Private Nostr Relay on Railway (I think??)
- 📋 What You’ll Need Before Starting
- 🚂 PART 1: Create Railway Account (5 minutes)
- 🔀 PART 2: Fork the Relay Code (5 minutes)
- 📝 PART 3: Configure Your Relay (10 minutes)
- 🚀 PART 4: Deploy to Railway (15 minutes)
- 🌐 PART 5: Generate Your Relay URL (5 minutes)
- 🔐 PART 6: Add Environment Variables (5 minutes)
- ✅ PART 7: Verify It’s Working (5 minutes)
- 🎊 YOU’RE DONE!
- 🔧 Maintenance & Troubleshooting
- 🌟 Next Steps:
- 💜 Share This Guide!
🚂 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:
-
If you have an npub, convert it at: https://nostr.band/converter
-
Or check your Nostr profile in any client
🚂 PART 1: Create Railway Account (5 minutes)
Step 1: Sign Up for Railway
-
Go to:
https://railway.app -
Click “Login” (top right)
-
Click “Login with GitHub”
If you don’t have GitHub:
-
Go to
https://github.comfirst -
Click “Sign up”
-
Use your email and create a password
-
Verify your email
-
Return to Railway and login with GitHub
-
Click “Authorize Railway” when GitHub asks
-
✅ 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
-
Open new tab:
https://github.com/scsibug/nostr-rs-relay -
Click “Fork” button (top right)
-
Click “Create fork” (green button)
-
Wait 10 seconds
-
✅ You now have:
github.com/YOUR-USERNAME/nostr-rs-relay
📝 PART 3: Configure Your Relay (10 minutes)
Step 3: Edit the Config File
-
In your forked repo, click
config.toml -
Click the pencil icon ✏️ (Edit this file)
-
Delete everything in the file
-
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`
-
Scroll down
-
Commit message:
Configure relay with my settings -
Click “Commit changes”
Note: You’ll update the relay_url later once Railway gives you the URL.
Step 4: Update the Dockerfile
-
In your repo, click
Dockerfile -
Click pencil ✏️ to edit
-
Delete everything
-
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`
-
Scroll down
-
Commit message:
Add config file to Docker build -
Click “Commit changes”
🚀 PART 4: Deploy to Railway (15 minutes)
Step 5: Create Railway Project
-
Go back to Railway:
https://railway.app -
Click “New Project” (purple button)
-
Click “Deploy from GitHub repo”
-
Click “Configure GitHub App”
-
Select “Only select repositories”
-
Choose
nostr-rs-relayfrom the dropdown -
Click “Install & Authorize”
Step 6: Deploy Your Relay
-
You should see
nostr-rs-relayin the list -
Click on it
-
Click “Deploy Now”
-
Wait 7-10 minutes - Railway is building (Rust takes time!)
-
Watch for “Deployed” or green checkmark ✅
🌐 PART 5: Generate Your Relay URL (5 minutes)
Step 7: Get Your Public URL
-
Click on your deployed nostr-rs-relay service
-
Click “Settings” tab
-
Scroll to “Networking” section
-
Click “Generate Domain”
-
Railway creates a URL like:
nostr-rs-relay-production-XXXX.up.railway.app -
Copy this URL!
Step 8: Update Config with Your Real URL
-
Go back to GitHub:
github.com/YOUR-USERNAME/nostr-rs-relay -
Click
config.toml -
Click pencil ✏️ to edit
-
Find line 2:
relay_url = "wss://YOUR-RELAY-URL-WILL-GO-HERE.up.railway.app" -
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" -
Commit message:
Update relay URL with actual domain -
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
-
In Railway, click your nostr-rs-relay service
-
Click “Variables” tab
-
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
- 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
-
In Railway, click your service
-
Click “Deployments” tab
-
Click on the latest ACTIVE deployment (green checkmark)
-
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
-
Go to:
https://websocketking.com -
Enter your relay URL:
wss://nostr-rs-relay-production-XXXX.up.railway.app -
Click “Connect”
-
✅ 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:
-
Go to GitHub →
config.toml -
Edit the
pubkey_whitelistsection:[authorization] pubkey_whitelist = [ "YOUR_ADMIN_PUBKEY_HEX", "MEMBER_1_PUBKEY_HEX", "MEMBER_2_PUBKEY_HEX" ] -
Commit changes
-
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:
-
Connect your Nostr app to this relay
-
Publish encrypted events (private data)
-
Create NIP-29 private communities
-
Build member-only platforms
-
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! ⚡