Cloudflare SSL/TLS Modes & Origin CA Certificates
Master Cloudflare SSL encryption modes (Flexible vs Full vs Full Strict), generate 15-year Origin CA certificates for Nginx, and fix infinite redirect loops.
Cloudflare SSL/TLS Modes & Origin CA Certificates
Configuring the correct SSL/TLS encryption mode in Cloudflare ensures end-to-end data security and eliminates common configuration errors like redirect loops.
1. Cloudflare SSL/TLS Encryption Modes Compared
1. Flexible (Vulnerable!):
[ Browser ] βββ HTTPS (Encrypted) ββββΊ [ Cloudflare ] βββ Plain HTTP (Unencrypted!) ββββΊ [ Origin VPS ]
2. Full:
[ Browser ] βββ HTTPS (Encrypted) ββββΊ [ Cloudflare ] βββ HTTPS (Self-Signed Allowed) βββΊ [ Origin VPS ]
3. Full (Strict) - PRODUCTION STANDARD:
[ Browser ] βββ HTTPS (Encrypted) ββββΊ [ Cloudflare ] βββ HTTPS (Trusted / Origin CA) ββΊ [ Origin VPS ]| Mode | Visitor to Cloudflare | Cloudflare to Origin | Security Rating |
|---|---|---|---|
| Off | HTTP | HTTP | β Insecure |
| Flexible | HTTPS | HTTP (Plaintext) | β Dangerous (Vulnerable to eavesdropping; causes redirect loops) |
| Full | HTTPS | HTTPS (Untrusted/Self-signed) | β οΈ Partial |
| Full (Strict) | HTTPS | HTTPS (Verified Valid Certificate) | β Production Standard |
2. Generating Cloudflare 15-Year Origin CA Certificates
Cloudflare provides free SSL certificates valid for up to 15 years specifically designed for your origin server.
Step 1: Create Origin Certificate in Cloudflare
- In Cloudflare Dashboard, go to SSL/TLS -> Origin Server -> Create Certificate.
- Keep RSA (2048) and list your hostnames:
example.com,*.example.com. - Set Validity to 15 years.
- Click Create.
Step 2: Save Certificates on your Ubuntu VPS
Save the certificate to /etc/ssl/certs/cloudflare-origin.pem and the private key to /etc/ssl/private/cloudflare-origin.key:
sudo chmod 600 /etc/ssl/private/cloudflare-origin.keyStep 3: Configure Nginx Server Block
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name example.com www.example.com;
ssl_certificate /etc/ssl/certs/cloudflare-origin.pem;
ssl_certificate_key /etc/ssl/private/cloudflare-origin.key;
# SSL protocols
ssl_protocols TLSv1.2 TLSv1.3;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_cf_connecting_ip;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Step 4: Set Mode to Full (Strict) in Cloudflare Dashboard
Go to SSL/TLS -> Overview and select Full (Strict).
3. Fixing ERR_TOO_MANY_REDIRECTS (Infinite Loop)
The Cause:
If Cloudflare is set to Flexible mode, Cloudflare connects to your VPS over port 80 (HTTP). If Nginx has a rule saying return 301 https://$host$request_uri;, Nginx sends a redirect back to Cloudflare. Cloudflare requests HTTP again, causing an infinite redirect loop.
The Fix:
Change Cloudflare SSL mode to Full (Strict) and ensure your origin VPS is listening on port 443 with SSL enabled.
Cloudflare Proxy Modes (Orange vs Grey Cloud) & CDN Caching
Understand Proxied vs DNS-only records, edge CDN caching mechanisms, cache purging, and how to bypass edge caching on authenticated sessions.
Cloudflare WAF, Security & Rate Limiting
Protect origins from Layer 7 attacks using Cloudflare WAF, custom firewall rules, Bot Fight Mode, rate limiting, and restoring true client IPs in Nginx.