- Move all deployment documentation to docs/deployment/ (16 files) - Move all phase documentation to docs/phases/ (9 files) - Move deployment scripts to scripts/ (3 PowerShell scripts) - Remove temporary deployment zip files (5 files) - Remove duplicate documentation files - Create documentation indexes for better navigation - Clean up root directory to essential files only - Update documentation references Root directory reduced from ~50+ files to 20 essential files. All documentation properly organized and indexed.
7.6 KiB
7.6 KiB
☁️ Cloudflare Setup Guide for mim4u.org
This guide provides step-by-step instructions for configuring Cloudflare for the Miracles in Motion application.
📋 Prerequisites
- Cloudflare account
- Domain
mim4u.orgregistered - Access to domain registrar DNS settings
- Cloudflare API token (optional, for automation)
🚀 Step-by-Step Setup
Step 1: Add Domain to Cloudflare
- Log in to Cloudflare Dashboard
- Click "Add a site"
- Enter your domain:
mim4u.org - Select a plan (Free plan is sufficient)
- Cloudflare will scan your existing DNS records
Step 2: Update Nameservers
- Cloudflare will provide you with nameservers (e.g.,
ns1.cloudflare.com,ns2.cloudflare.com) - Go to your domain registrar
- Update nameservers to Cloudflare's nameservers
- Wait for DNS propagation (24-48 hours, usually faster)
Step 3: Configure DNS Records
Once nameservers are updated, configure DNS records:
Option A: Using Cloudflare Dashboard
- Go to DNS → Records
- Delete any existing A records for
@(apex domain) - Add the following records:
| Type | Name | Content | Proxy Status | TTL |
|---|---|---|---|---|
| CNAME | www | lemon-water-015cb3010.3.azurestaticapps.net | ✅ Proxied | Auto |
| CNAME | @ | lemon-water-015cb3010.3.azurestaticapps.net | ⚠️ DNS Only | Auto |
Important Notes:
- For apex domain (
@), Cloudflare uses CNAME Flattening automatically - Set apex domain to DNS Only (gray cloud) initially for Azure validation
- After Azure validation, you can enable proxying (orange cloud)
Option B: Using Azure Static Web App Validation
If Azure requires TXT validation:
-
Get validation token from Azure:
az staticwebapp hostname show \ --name mim-prod-igiay4-web \ --resource-group rg-miraclesinmotion-prod \ --hostname "mim4u.org" \ --query "validationToken" -o tsv -
Add TXT record in Cloudflare:
- Type:
TXT - Name:
_asuidorasuid - Content: (validation token from Azure)
- TTL: Auto
- Type:
Step 4: Configure SSL/TLS
- Go to SSL/TLS → Overview
- Set encryption mode to Full (strict)
- Enable Always Use HTTPS:
- Go to SSL/TLS → Edge Certificates
- Toggle Always Use HTTPS to ON
- Enable Automatic HTTPS Rewrites:
- Toggle Automatic HTTPS Rewrites to ON
Step 5: Configure Page Rules
- Go to Rules → Page Rules
- Create the following rules:
Rule 1: Force HTTPS
- URL:
*mim4u.org/* - Settings:
- Always Use HTTPS: ✅ ON
- SSL: Full (strict)
Rule 2: Cache Static Assets
- URL:
*mim4u.org/assets/* - Settings:
- Cache Level: Cache Everything
- Edge Cache TTL: 1 month
Rule 3: Cache JS/CSS
- URL:
*mim4u.org/*.jsor*mim4u.org/*.css - Settings:
- Cache Level: Cache Everything
- Edge Cache TTL: 1 week
Step 6: Configure Security Settings
- Go to Security → Settings
- Configure:
- Security Level: Medium
- Challenge Passage: 30 minutes
- Browser Integrity Check: ✅ On
- Privacy Pass Support: ✅ On
Step 7: Configure Firewall Rules
- Go to Security → WAF → Custom rules
- Create rules:
Rule: Block Bad Bots
- Expression:
(http.user_agent contains "bot" and not http.user_agent contains "Googlebot") - Action: Block
Rule: Rate Limiting for API
- Expression:
(http.request.uri.path contains "/api/") - Action: Challenge
- Rate: 100 requests per minute
Step 8: Configure Speed Optimization
- Go to Speed → Optimization
- Enable:
- ✅ Auto Minify (JavaScript, CSS, HTML)
- ✅ Brotli compression
- ✅ Rocket Loader (optional)
- ✅ Mirage (optional, for mobile)
Step 9: Configure Analytics
- Go to Analytics → Web Analytics
- Enable Web Analytics for your domain
- (Optional) Add tracking script to your application
Step 10: Add Custom Domain to Azure
After DNS is configured and validated:
# Add custom domain to Static Web App
az staticwebapp hostname set \
--name mim-prod-igiay4-web \
--resource-group rg-miraclesinmotion-prod \
--hostname "mim4u.org"
az staticwebapp hostname set \
--name mim-prod-igiay4-web \
--resource-group rg-miraclesinmotion-prod \
--hostname "www.mim4u.org"
✅ Verification Steps
1. Verify DNS Resolution
# Check DNS records
dig mim4u.org
dig www.mim4u.org
# Check CNAME
dig www.mim4u.org CNAME
# Check Cloudflare proxy status
curl -I https://mim4u.org | grep -i "cf-"
Expected headers:
CF-Cache-Status: DYNAMICCF-Ray: [unique-id]Server: cloudflare
2. Verify SSL/TLS
# Test HTTPS
curl -I https://mim4u.org
# Check SSL certificate
openssl s_client -connect mim4u.org:443 -servername mim4u.org
3. Verify Cloudflare Configuration
# Test Cloudflare headers
curl -I https://mim4u.org | grep -i "cf-"
# Test caching
curl -I https://mim4u.org/assets/ | grep -i "cf-cache"
🔧 Automation (Optional)
Using Cloudflare API
If you have a Cloudflare API token:
# Set environment variables
export CLOUDFLARE_API_TOKEN="your-api-token"
export CLOUDFLARE_ZONE_ID="your-zone-id"
# Create CNAME record via API
curl -X POST "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE_ID/dns_records" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-H "Content-Type: application/json" \
--data '{
"type": "CNAME",
"name": "www",
"content": "lemon-water-015cb3010.3.azurestaticapps.net",
"proxied": true
}'
⚠️ Important Notes
- DNS Propagation: Changes can take 24-48 hours to propagate globally
- SSL Certificate: Azure will automatically provision SSL certificates after DNS validation
- CNAME Flattening: Cloudflare automatically handles CNAME flattening for apex domains
- Proxy Status: Keep apex domain as DNS Only until Azure validation completes
- Cache Purging: Use Cloudflare dashboard to purge cache when deploying updates
🔍 Troubleshooting
Issue: DNS not resolving
- Solution: Wait for DNS propagation (up to 48 hours)
- Check nameservers are correctly set at registrar
- Verify DNS records in Cloudflare dashboard
Issue: SSL certificate errors
- Solution: Ensure SSL mode is "Full (strict)"
- Verify DNS records are correct
- Wait for Azure SSL certificate provisioning
Issue: Site not loading through Cloudflare
- Solution: Check proxy status (should be orange cloud for www)
- Verify CNAME records point to correct Azure endpoint
- Check Cloudflare firewall rules
Issue: Cache not updating
- Solution: Purge cache in Cloudflare dashboard
- Adjust cache TTL settings
- Use cache rules for specific paths
📊 Performance Optimization
Recommended Settings:
-
Caching:
- Static assets: Cache Everything (1 month)
- HTML: Bypass Cache
- API endpoints: Bypass Cache
-
Compression:
- Enable Brotli compression
- Enable Gzip compression
-
Minification:
- Auto Minify JavaScript
- Auto Minify CSS
- Auto Minify HTML
-
Image Optimization:
- Enable Polish (if on paid plan)
- Enable WebP conversion
📝 Current Status
- Cloudflare Account: ⚠️ Needs to be created/configured
- DNS Records: ⚠️ Pending configuration
- SSL/TLS: ⚠️ Pending (will be automatic after DNS)
- Azure Integration: ✅ Ready
Next Steps:
- Create/access Cloudflare account
- Add domain to Cloudflare
- Update nameservers at registrar
- Configure DNS records
- Set up SSL/TLS and security settings
- Add custom domain to Azure Static Web App