NGINX Configuration
🌐 What NGINX Does for VoP
Section titled “🌐 What NGINX Does for VoP”NGINX acts as your security gateway and performance booster:
Internet → NGINX → VoP API → Database ↓ ↓ ↓ ↓ SSL Security Business Encrypted Validation Logic Storage
🔒 Security Features
Section titled “🔒 Security Features”- SSL/TLS termination - Handles all encryption
- Client certificate validation - Blocks unauthorized access
- Rate limiting - Prevents abuse and DDoS
- Security headers - Protects against common attacks
⚡ Performance Features
Section titled “⚡ Performance Features”- Load balancing - Distributes traffic across multiple VoP instances
- Caching - Speeds up responses
- Compression - Reduces bandwidth usage
- Connection pooling - Efficient resource usage
Automatic Setup
Section titled “Automatic Setup”🚀 One-Command Configuration
Section titled “🚀 One-Command Configuration”# NGINX is automatically configured when you run:make setup-epc-complete
# This sets up:# ✅ SSL certificates# ✅ NGINX configuration# ✅ Security headers# ✅ Rate limiting# ✅ Load balancing
📁 Configuration Files
Section titled “📁 Configuration Files”nginx/├── nginx.conf # Main configuration├── ssl.conf # SSL settings├── security.conf # Security headers└── upstream.conf # Load balancing
Key Configuration Highlights
Section titled “Key Configuration Highlights”🔐 SSL Security (Bank-Grade)
Section titled “🔐 SSL Security (Bank-Grade)”# TLS 1.3+ only (latest security)ssl_protocols TLSv1.2 TLSv1.3;
# Client certificate required (mTLS)ssl_client_certificate /etc/nginx/certs/ca.crt;ssl_verify_client on;
# Strong encryption ciphersssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
🛡️ Security Headers
Section titled “🛡️ Security Headers”# Prevent clickjackingadd_header X-Frame-Options DENY always;
# Prevent MIME type sniffingadd_header X-Content-Type-Options nosniff always;
# Force HTTPS for 1 yearadd_header Strict-Transport-Security "max-age=31536000" always;
# Content Security Policyadd_header Content-Security-Policy "default-src 'self'" always;
⚡ Rate Limiting
Section titled “⚡ Rate Limiting”# Limit API requests to prevent abuselimit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
# Allow burst of 20 requests, then rate limitlimit_req zone=api burst=20 nodelay;
Testing NGINX Setup
Section titled “Testing NGINX Setup”✅ 1. Check NGINX is Running
Section titled “✅ 1. Check NGINX is Running”# Check NGINX statusdocker-compose ps nginx
# Should show: Up and healthy
✅ 2. Test SSL Configuration
Section titled “✅ 2. Test SSL Configuration”# Test HTTPS endpointcurl -k https://localhost:443/health
# Expected: {"status": "healthy"}
✅ 3. Test Client Certificate Authentication
Section titled “✅ 3. Test Client Certificate Authentication”# With client certificate (should work)curl --cert certs/client/client.crt \ --key certs/client/client.key \ https://localhost:443/health
# Without client certificate (should fail)curl https://localhost:443/health# Expected: 403 Forbidden
✅ 4. Test Rate Limiting
Section titled “✅ 4. Test Rate Limiting”# Send many requests quicklyfor i in {1..25}; do curl -s -o /dev/null -w "%{http_code}\n" \ --cert certs/client/client.crt \ --key certs/client/client.key \ https://localhost:443/healthdone
# Expected: First 20 return 200, then 429 (rate limited)
Common NGINX Commands
Section titled “Common NGINX Commands”🔧 Service Management
Section titled “🔧 Service Management”# Start NGINXdocker-compose up -d nginx
# Stop NGINXdocker-compose stop nginx
# Restart NGINXdocker-compose restart nginx
# Reload configuration (no downtime)docker-compose exec nginx nginx -s reload
📊 Monitoring
Section titled “📊 Monitoring”# View NGINX logsdocker-compose logs -f nginx
# Check NGINX statuscurl http://localhost:8080/nginx-status
# Test configuration syntaxdocker-compose exec nginx nginx -t
🔍 SSL Testing
Section titled “🔍 SSL Testing”# Test SSL configurationopenssl s_client -connect localhost:443 -servername localhost
# Check certificate detailsopenssl s_client -connect localhost:443 -showcerts
# Test specific TLS versionopenssl s_client -connect localhost:443 -tls1_3
Load Balancing (Multiple VoP Instances)
Section titled “Load Balancing (Multiple VoP Instances)”📈 Scale VoP Service
Section titled “📈 Scale VoP Service”services: vop-service: deploy: replicas: 3 # Run 3 VoP instances
⚖️ NGINX Load Balancing
Section titled “⚖️ NGINX Load Balancing”# Automatically configured upstreamupstream vop_backend { least_conn; # Route to least busy instance server vop-service-1:8443; server vop-service-2:8443; server vop-service-3:8443;}
Performance Optimization
Section titled “Performance Optimization”🚀 Built-in Optimizations
Section titled “🚀 Built-in Optimizations”- HTTP/2 - Faster connection handling
- Gzip compression - Reduces response size by 70%
- Keep-alive connections - Reuses connections efficiently
- Static file caching - Serves files directly from memory
📊 Performance Metrics
Section titled “📊 Performance Metrics”# Expected performance:# - Response time: < 100ms (NGINX overhead)# - Throughput: 10,000+ requests/second# - SSL handshake: < 50ms# - Memory usage: 10-50MB
Security Features
Section titled “Security Features”🔒 Client Certificate Validation
Section titled “🔒 Client Certificate Validation”# Only clients with valid certificates can accessssl_verify_client on;ssl_verify_depth 2;
# Certificate information passed to VoP APIproxy_set_header X-Client-Cert $ssl_client_cert;proxy_set_header X-Client-Verify $ssl_client_verify;
🛡️ DDoS Protection
Section titled “🛡️ DDoS Protection”# Rate limiting per IPlimit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
# Rate limiting per client certificatelimit_req_zone $ssl_client_s_dn zone=client_cert:10m rate=100r/s;
# Connection limitinglimit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;limit_conn conn_limit_per_ip 10;
Troubleshooting
Section titled “Troubleshooting”🚫 NGINX Won’t Start
Section titled “🚫 NGINX Won’t Start”# Check configuration syntaxdocker-compose exec nginx nginx -t
# Check logs for errorsdocker-compose logs nginx
# Common fix: regenerate certificatesmake generate-docker-certsdocker-compose restart nginx
🔐 SSL Certificate Errors
Section titled “🔐 SSL Certificate Errors”# Check certificate validityopenssl x509 -in certs/server/server.crt -noout -dates
# Verify certificate chainopenssl verify -CAfile certs/ca/ca.crt certs/server/server.crt
# Test SSL handshakeopenssl s_client -connect localhost:443
🌐 Connection Issues
Section titled “🌐 Connection Issues”# Check if NGINX is listeningnetstat -tlnp | grep :443
# Test backend connectivitydocker-compose exec nginx curl -k https://vop-service:8443/health
# Check upstream statuscurl http://localhost:8080/nginx-status
📈 Performance Issues
Section titled “📈 Performance Issues”# Check NGINX resource usagedocker stats vop-nginx
# Monitor active connectionscurl http://localhost:8080/nginx-status
# Check for errors in logsgrep "error" /var/log/nginx/error.log
Custom Configuration
Section titled “Custom Configuration”🎛️ Environment-Specific Settings
Section titled “🎛️ Environment-Specific Settings”Development:
# Relaxed security for developmentssl_verify_client optional;access_log /var/log/nginx/access.log debug;
Production:
# Maximum security for productionssl_verify_client on;ssl_protocols TLSv1.3; # TLS 1.3 onlyadd_header Strict-Transport-Security "max-age=31536000; preload";
🌍 Custom Domain Setup
Section titled “🌍 Custom Domain Setup”# Configure for your domainmake setup-nginx-domain DOMAIN=api.yourcompany.com
# This updates:# - Server name in NGINX config# - SSL certificate with your domain# - DNS configuration examples
Integration Examples
Section titled “Integration Examples”💻 Application Integration
Section titled “💻 Application Integration”// Your app connects through NGINXconst response = await fetch('https://your-domain.com/api/v1/verify', { method: 'POST', // NGINX handles SSL termination and client certificates headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ iban, name })});
☁️ Cloud Load Balancer Integration
Section titled “☁️ Cloud Load Balancer Integration”# Export NGINX config for cloud load balancersmake export-nginx-config-awsmake export-nginx-config-gcpmake export-nginx-config-azure