4.7 KiB
4.7 KiB
DNS Migration and SSL Setup Guide for Tilbudgivern
Current Status
✅ Application is running locally on the new server ✅ Database migrated successfully (47 tables, 33k+ products) ✅ Nginx configured and serving the application ✅ PM2 managing the Node.js backend ✅ Certbot installed for SSL certificates
Pre-Migration Checklist
1. Verify Application is Working
# Test local application
curl -I http://localhost
curl -s http://localhost/api/health | jq
# Check database
mysql -u tilbudgivern_service -p'REDACTED_PASSWORD' -e "USE tilbudgivern; SELECT COUNT(*) FROM bygma_products;"
# Verify PM2 status
pm2 list
2. Update Nginx Configuration for Domain
# Replace current config with SSL-ready version
sudo cp nginx-ssl-ready.conf /etc/nginx/sites-available/tilbudgivern
sudo nginx -t
sudo systemctl reload nginx
DNS Migration Steps
Step 1: Prepare SSL Certificate (Before DNS Change)
IMPORTANT: Run this BEFORE changing DNS
- Test certificate issuance in staging mode:
sudo certbot --nginx --staging -d tilbudsgiveren.alw.dk -d www.tilbudsgiveren.alw.dk --non-interactive --agree-tos --email your-email@domain.com
- If staging works, get real certificate:
sudo certbot --nginx -d tilbudsgiveren.alw.dk -d www.tilbudsgiveren.alw.dk --non-interactive --agree-tos --email your-email@domain.com
Step 2: Update Cloudflare DNS
In Cloudflare Dashboard:
-
Change A record for
tilbudsgiveren.alw.dk- Current: Points to old server IP
- New: Point to this server's IP:
65.109.226.241
-
Change A record for
www.tilbudsgiveren.alw.dk- New: Point to this server's IP:
65.109.226.241
- New: Point to this server's IP:
-
Update proxy settings:
- Turn OFF Cloudflare proxy (gray cloud) during migration
- Turn back ON after confirming SSL works
Step 3: Verify Migration
After DNS propagation (5-15 minutes):
# Check DNS resolution
nslookup tilbudsgiveren.alw.dk
nslookup www.tilbudsgiveren.alw.dk
# Test HTTPS access
curl -I https://tilbudsgiveren.alw.dk
curl -s https://tilbudsgiveren.alw.dk/api/health | jq
# Check SSL certificate
echo | openssl s_client -servername tilbudsgiveren.alw.dk -connect tilbudsgiveren.alw.dk:443 2>/dev/null | openssl x509 -noout -dates
Step 4: Update Frontend Configuration
If frontend has hardcoded API URLs, update them:
# Check current frontend build for API URLs
grep -r "tilbudsgiveren.alw.dk" frontend/build/ || echo "No hardcoded URLs found"
# If needed, rebuild frontend with production environment
cd frontend
npm run build
SSL Certificate Management
Auto-renewal setup (already configured):
# Check certbot timer status
sudo systemctl status certbot.timer
# Test renewal (dry-run)
sudo certbot renew --dry-run
Manual renewal if needed:
sudo certbot renew
sudo systemctl reload nginx
Monitoring Commands
Application Health:
# Overall status
./start-app.sh
# PM2 monitoring
pm2 monit
# Nginx logs
sudo tail -f /var/log/nginx/tilbudgivern_access.log
sudo tail -f /var/log/nginx/tilbudgivern_error.log
# Application logs
pm2 logs tilbudgivern-app --no-stream
Database Health:
# Connection test
mysql -u tilbudgivern_service -p'REDACTED_PASSWORD' -e "USE tilbudgivern; SELECT 'OK' as status;"
# Data verification
mysql -u tilbudgivern_service -p'REDACTED_PASSWORD' -e "
USE tilbudgivern;
SELECT 'bygma_products' as table_name, COUNT(*) as records FROM bygma_products
UNION ALL
SELECT 'materials', COUNT(*) FROM materials
UNION ALL
SELECT 'custom_packages', COUNT(*) FROM custom_packages;
"
Rollback Plan (If Needed)
If issues arise, quickly rollback DNS:
- Change Cloudflare A records back to old server IP
- Wait for DNS propagation
- Old server will handle traffic while you fix issues
Post-Migration Tasks
- Re-enable Cloudflare proxy after confirming SSL works
- Update monitoring to point to new server
- Update backup scripts for new server location
- Test all application features thoroughly
- Update any external integrations with new server details
Server Information
- Server IP:
65.109.226.241 - Application Port: 4031
- Nginx Config: /etc/nginx/sites-available/tilbudgivern
- SSL Certs: /etc/letsencrypt/live/tilbudsgiveren.alw.dk/
- Database: MySQL with tilbudgivern_service user
- PM2 Process: tilbudgivern-app
- Frontend Build: /mnt/HC_Volume_103713257/tilbudgivern/frontend/build
Support Commands
# Quick application restart
pm2 restart tilbudgivern-app
# Full system restart
sudo systemctl restart nginx
sudo systemctl restart mariadb
pm2 restart tilbudgivern-app
# Check all services
sudo systemctl status nginx mariadb
pm2 status
# Run build and test
./build-and-test.sh