Guide to deploying ChainViz on Amazon Web Services (AWS).
This guide covers deploying ChainViz on AWS using:
- EC2 for compute
- Docker for containerization
- Nginx for reverse proxy
- SSL/TLS with Let's Encrypt
- AWS account with EC2 access
- Domain name (optional, for SSL)
- SSH key pair for EC2 access
- Docker installed locally
Recommended: t3.medium or larger
- 2 vCPUs
- 4 GB RAM
- Good for small to medium workloads
For production: t3.large or t3.xlarge
- More resources
- Better performance
- Handles more concurrent users
- Go to EC2 Console: https://console.aws.amazon.com/ec2/
- Click "Launch Instance"
- Configure:
- Name:
chainviz-server - AMI: Ubuntu Server 22.04 LTS
- Instance Type: t3.medium
- Key Pair: Select or create new
- Network: Default VPC
- Storage: 20 GB gp3
- Security Group: Create new (see below)
- Name:
Inbound Rules:
- SSH (22): Your IP only
- HTTP (80): 0.0.0.0/0 (all)
- HTTPS (443): 0.0.0.0/0 (all)
- Custom TCP (8000): Your IP only (backend)
Outbound Rules:
- All traffic: 0.0.0.0/0
# Get your instance IP
aws ec2 describe-instances --instance-ids i-xxxxxxxxx
# SSH into instance
ssh -i your-key.pem ubuntu@your-instance-ipsudo apt update
sudo apt upgrade -y# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Add user to docker group
sudo usermod -aG docker ubuntu
# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Verify installation
docker --version
docker-compose --versionsudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx# Create app directory
mkdir -p /home/ubuntu/apps
cd /home/ubuntu/apps
# Clone repository
git clone https://github.com/yourusername/ChainViz.git
cd ChainViz# Create .env file
cat > .env << EOF
# Electrum Server
ELECTRUM_HOST=fulcrum.sethforprivacy.com
ELECTRUM_PORT=50002
ELECTRUM_USE_SSL=true
# Redis
REDIS_HOST=redis
REDIS_PORT=6379
# Frontend
VITE_API_URL=http://your-domain.com:8000
EOF# Build and start
docker-compose up -d --build
# Check status
docker-compose ps
# View logs
docker-compose logs -fsudo nano /etc/nginx/sites-available/chainvizContent:
server {
listen 80;
server_name your-domain.com;
# Frontend
location / {
proxy_pass http://localhost:5173;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Backend API
location /api {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Backend WebSocket
location /ws {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}# Create symlink
sudo ln -s /etc/nginx/sites-available/chainviz /etc/nginx/sites-enabled/
# Test configuration
sudo nginx -t
# Reload Nginx
sudo systemctl reload nginxsudo apt install certbot python3-certbot-nginx -y# Replace with your domain
sudo certbot --nginx -d your-domain.com
# Follow prompts:
# - Enter email
# - Agree to terms
# - Choose to redirect HTTP to HTTPS# Test renewal
sudo certbot renew --dry-run
# Certbot auto-renews certificates
# Check with: sudo systemctl status certbot.timerA Record:
Type: A
Name: @
Value: your-instance-ip
TTL: 300
CNAME (optional):
Type: CNAME
Name: www
Value: your-domain.com
TTL: 300
# Check DNS propagation
dig your-domain.com
# Should return your instance IP# Enable UFW
sudo ufw enable
# Allow SSH
sudo ufw allow 22/tcp
# Allow HTTP/HTTPS
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# Check status
sudo ufw status# Docker logs
docker-compose logs -f
# Nginx logs
sudo tail -f /var/log/nginx/access.log
sudo tail -f /var/log/nginx/error.log
# System logs
sudo journalctl -u nginx -f# Docker services
docker-compose ps
# Nginx
sudo systemctl status nginx
# Certbot
sudo systemctl status certbot.timerSee Auto-Deploy Guide for automated deployments.
#!/bin/bash
# deploy.sh
cd /home/ubuntu/apps/ChainViz
git pull
docker-compose down
docker-compose up -d --build
docker-compose logs -fMake executable:
chmod +x deploy.shCheck Docker:
docker-compose logs
docker-compose psCheck ports:
sudo netstat -tlnp | grep -E ':(80|443|8000|5173)'Check backend:
curl http://localhost:8000/api/configCheck Nginx config:
sudo nginx -tCheck logs:
sudo tail -f /var/log/nginx/error.logCheck certificate:
sudo certbot certificatesRenew certificate:
sudo certbot renewCheck auto-renewal:
sudo systemctl status certbot.timerCheck memory:
free -h
docker statsIncrease swap:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfileSave up to 90% on compute costs:
# Launch spot instance
aws ec2 request-spot-instances \
--spot-price "0.05" \
--instance-count 1 \
--type "one-time" \
--launch-specification file://spot-spec.jsonSave up to 75% with 1-year or 3-year commitments:
- Go to EC2 Console
- Click "Reserved Instances"
- Purchase RI for your instance type
Set up billing alerts:
- Go to CloudWatch Console
- Click "Billing"
- Create alarm for estimated charges
- Use SSH keys: Never use passwords
- Restrict SSH access: Only from your IP
- Keep system updated: Regular
apt update && apt upgrade - Use firewall: Configure UFW properly
- Enable SSL: Always use HTTPS
- Regular backups: Backup data and configurations
- Monitor logs: Check logs regularly
- Use IAM roles: For AWS API access
Increase instance size:
- Stop instance
- Change instance type
- Start instance
Use Load Balancer:
- Create Application Load Balancer
- Create target group
- Register instances
- Configure health checks
Set up auto-scaling group:
- Create launch template
- Create auto-scaling group
- Configure scaling policies
- Set up CloudWatch alarms
# Backup Docker volumes
docker run --rm -v chainviz_redis_data:/data -v $(pwd):/backup ubuntu tar czf /backup/redis-backup.tar.gz /data
# Backup configurations
tar czf config-backup.tar.gz .env docker-compose.yml nginx.conf# Restore Docker volumes
docker run --rm -v chainviz_redis_data:/data -v $(pwd):/backup ubuntu tar xzf /backup/redis-backup.tar.gz -C /
# Restore configurations
tar xzf config-backup.tar.gz- Set up Auto-Deploy for automated deployments
- Configure Monitoring for production
- Set up Backups for data protection
- See Troubleshooting for help
Happy deploying! ☁️