This guide provides step-by-step instructions for deploying the Nostr relay on DigitalOcean.
- A DigitalOcean account
- A domain name pointed to DigitalOcean nameservers
- SSH access to your DigitalOcean droplet
-
Create a new droplet with the following specifications:
- Ubuntu 22.04 LTS
- Basic Plan
- Regular CPU (Minimum 4GB RAM / 2 CPUs)
- Choose a datacenter region close to your target users
- Enable monitoring
- Add your SSH key
-
Create DNS records:
A record: relay.yourdomain.com → Your droplet IP
-
Prepare Your Environment File
Create a
.envfile with your configuration:# Database Configuration DATABASE_URL=postgresql://nostr_user:your_password_here@localhost:5432/nostr_relay DATABASE_MAX_CONNECTIONS=50 DATABASE_MIN_CONNECTIONS=5 DATABASE_SSL=true # Server Configuration PORT=3000 HOST=127.0.0.1 # Relay Information RELAY_NAME="Your Relay Name" RELAY_DESCRIPTION="Your relay description" RELAY_PUBKEY="your-relay-public-key" RELAY_CONTACT="admin@yourdomain.com"
-
Prepare Deployment Package
On your local machine:
# Create deployment package tar -czf nostr-relay-clean.tar.gz \ --exclude='node_modules' \ --exclude='.git' \ --exclude='*.log' \ .
-
Upload Files to Server
# Copy deployment files scp nostr-relay-clean.tar.gz root@your-droplet-ip:/tmp/ scp deploy/scripts/deploy-digitalocean.sh root@your-droplet-ip:/tmp/ scp .env root@your-droplet-ip:/tmp/ -
Run Deployment Script
SSH into your droplet:
ssh root@your-droplet-ip
Update the script variables:
vim /tmp/deploy-digitalocean.sh # Update DOMAIN and email addressRun the deployment:
chmod +x /tmp/deploy-digitalocean.sh /tmp/deploy-digitalocean.sh
-
Verify Installation
Test the NIP-11 information endpoint:
curl -i -H "Accept: application/nostr+json" https://relay.yourdomain.com -
Monitor the Application
Check PM2 status:
pm2 status pm2 logs maiqr-relay
-
Setup Database Backups
Create a backup script:
sudo -u postgres pg_dump nostr_relay > /opt/backups/nostr_relay_$(date +%Y%m%d).sql
Add to crontab:
0 0 * * * /path/to/backup-script.sh
-
Configure Monitoring
- Enable DigitalOcean monitoring
- Set up alerts for:
- CPU usage
- Memory usage
- Disk space
- Database connections
-
Firewall Rules
# Verify UFW status sudo ufw status -
SSL Certificate
# Check certificate status certbot certificates -
Database Security
# Check PostgreSQL configuration sudo -u postgres psql -c "SHOW ssl;" sudo -u postgres psql -c "SHOW max_connections;"
-
File Permissions
# Verify application permissions ls -la /opt/maiqr-relay
-
Log Rotation PM2 log rotation is configured automatically. Verify settings:
pm2 conf pm2-logrotate
-
Database Maintenance
# Run VACUUM ANALYZE weekly sudo -u postgres psql nostr_relay -c "VACUUM ANALYZE;"
-
SSL Certificate Renewal Certbot auto-renewal is configured. Verify with:
sudo certbot renew --dry-run
-
Updates
# System updates sudo apt update sudo apt upgrade # Node.js updates npm update
-
Check Application Logs
pm2 logs maiqr-relay
-
Check Nginx Logs
tail -f /var/log/nginx/error.log
-
Check Database Logs
tail -f /var/log/postgresql/postgresql-*.log -
Common Issues
-
If WebSocket connections fail:
# Check Nginx configuration nginx -t # Check PM2 status pm2 status
-
If database connections fail:
# Check PostgreSQL status systemctl status postgresql # Check connections sudo -u postgres psql -c "SELECT count(*) FROM pg_stat_activity;"
-
As your relay grows, consider:
-
Database Optimization
- Increase
shared_buffers - Tune
work_mem - Add indexes for common queries
- Increase
-
Application Scaling
- Increase PM2 instances
- Consider load balancing
- Monitor memory usage
-
Droplet Upgrades
- Monitor resource usage
- Plan for vertical scaling
- Consider horizontal scaling for high loads