This guide provides detailed instructions for deploying the Client Portal application across multiple regions (US and China) for optimal performance and compliance.
- Primary Region: US East (Virginia) or US West (Oregon)
- Database: MongoDB Atlas US region
- CDN: CloudFlare or AWS CloudFront
- Hosting: AWS, Google Cloud, or DigitalOcean
- Primary Region: Beijing or Shanghai
- Database: MongoDB Atlas Asia Pacific region
- CDN: Alibaba Cloud CDN or Tencent Cloud CDN
- Hosting: Alibaba Cloud, Tencent Cloud, or AWS China
-
Clone and Setup:
git clone <repository-url> cd client-portal
-
Configure Environment:
cp env.example .env # Edit .env with your configuration -
Start Services:
docker-compose up -d
-
Access Application:
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
- MongoDB: localhost:27017
-
EC2 Setup:
# Launch EC2 instance (t3.medium or larger) # Install Docker and Docker Compose sudo yum update -y sudo yum install -y docker sudo systemctl start docker sudo systemctl enable docker sudo usermod -a -G docker ec2-user
-
Deploy Application:
# Clone repository git clone <repository-url> cd client-portal # Configure environment cp env.example .env # Edit .env with production values # Start services docker-compose up -d
-
Configure Load Balancer:
- Create Application Load Balancer
- Configure target groups
- Set up SSL certificates
- Configure health checks
-
ECS Setup:
# Launch ECS instance # Install Docker sudo apt update sudo apt install -y docker.io docker-compose sudo systemctl start docker sudo systemctl enable docker
-
Deploy Application:
# Same steps as AWS deployment git clone <repository-url> cd client-portal cp env.example .env # Configure for China region docker-compose up -d
-
Configure SLB (Server Load Balancer):
- Create SLB instance
- Configure backend servers
- Set up SSL certificates
- Configure health checks
-
Create Clusters:
- US Region: Create cluster in US East or US West
- China Region: Create cluster in Asia Pacific (Singapore or Sydney)
-
Configure Network Access:
// Allow access from your application servers // Whitelist IP addresses or use VPC peering
-
Set Up Replica Sets:
// Configure replica sets for high availability // Set up automatic failover
-
Environment Variables:
# US Region MONGODB_URI=mongodb+srv://username:password@cluster-us.mongodb.net/client-portal?retryWrites=true&w=majority # China Region MONGODB_URI=mongodb+srv://username:password@cluster-asia.mongodb.net/client-portal?retryWrites=true&w=majority
-
Add Domain:
- Add your domain to CloudFlare
- Configure DNS records
- Enable SSL/TLS
-
Configure Caching:
// Cache static assets // Configure page rules for API routes
-
Security Settings:
- Enable DDoS protection
- Configure WAF rules
- Set up rate limiting
-
Create CDN Domain:
- Add your domain
- Configure origin server
- Set up SSL certificates
-
Configure Caching:
// Cache static assets // Configure cache policies
-
Security Settings:
- Enable DDoS protection
- Configure access control
- Set up rate limiting
-
Obtain Certificates:
- Use Let's Encrypt for free certificates
- Or purchase from certificate authority
- Configure for both domains
-
Configure Nginx:
server { listen 443 ssl http2; server_name your-domain.com; ssl_certificate /path/to/certificate.crt; ssl_certificate_key /path/to/private.key; # SSL configuration ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512; ssl_prefer_server_ciphers off; }
-
AWS Security Groups:
# Allow HTTP (80) and HTTPS (443) # Allow SSH (22) from your IP # Allow MongoDB (27017) from application servers
-
Alibaba Cloud Security Groups:
# Same configuration as AWS # Configure security group rules
-
Health Checks:
# Configure health check endpoints curl http://your-domain.com/api/health -
Log Management:
# Configure log rotation # Set up log aggregation # Monitor error rates
-
Performance Monitoring:
- Set up APM tools
- Monitor response times
- Track resource usage
-
MongoDB Atlas Monitoring:
- Monitor connection counts
- Track query performance
- Set up alerts
-
Backup Strategy:
- Configure automated backups
- Test restore procedures
- Set up cross-region replication
-
AWS ALB Configuration:
# Configure target groups # Set up health checks # Configure SSL termination
-
Alibaba Cloud SLB:
# Configure backend servers # Set up health checks # Configure SSL termination
-
AWS Auto Scaling:
# Configure auto scaling groups # Set up scaling policies # Configure launch templates
-
Alibaba Cloud Auto Scaling:
# Configure scaling groups # Set up scaling rules # Configure launch templates
#!/bin/bash
# deploy.sh
set -e
echo "Starting deployment..."
# Pull latest code
git pull origin main
# Build and deploy
docker-compose down
docker-compose build --no-cache
docker-compose up -d
# Wait for services to be ready
sleep 30
# Run health checks
curl -f http://localhost:5000/api/health || exit 1
echo "Deployment completed successfully!"#!/bin/bash
# migrate.sh
set -e
echo "Running database migrations..."
# Connect to MongoDB and run migrations
mongo $MONGODB_URI --eval "
// Add any database migrations here
print('Migrations completed successfully!');
"
echo "Database migrations completed!"- Environment variables configured
- Database connections tested
- SSL certificates installed
- DNS records configured
- Firewall rules set up
- Monitoring configured
- Backup strategy implemented
- Load balancer configured
- Health checks working
- Security headers configured
-
Database Connection Issues:
# Check MongoDB connection mongo $MONGODB_URI --eval "db.adminCommand('ping')"
-
SSL Certificate Issues:
# Test SSL configuration openssl s_client -connect your-domain.com:443 -
Performance Issues:
# Check resource usage docker stats # Check logs docker-compose logs
- US Region: support-us@yourcompany.com
- China Region: support-cn@yourcompany.com
- Technical Issues: tech-support@yourcompany.com
-
Indexing:
// Ensure proper indexes are created db.submissions.createIndex({ "formId": 1, "status": 1 }); db.submissions.createIndex({ "createdAt": -1 });
-
Query Optimization:
// Use explain() to analyze queries db.submissions.find({ status: "pending" }).explain("executionStats");
-
Caching:
// Implement Redis caching // Cache frequently accessed data
-
CDN Configuration:
# Cache static assets # Configure cache headers
-
GDPR Compliance (EU):
- Implement data retention policies
- Provide data export functionality
- Configure consent management
-
China Data Protection:
- Store data within China
- Implement data localization
- Follow local regulations
-
ISO 27001:
- Implement security controls
- Regular security audits
- Incident response procedures
-
SOC 2:
- Implement access controls
- Monitor system access
- Regular compliance reviews
This deployment guide ensures your Client Portal application is properly configured for cross-region deployment with optimal performance, security, and compliance.