Secure a VPS with Cloudflare SSL (Full Strict)
Step 1: Add the domain to Cloudflare
Create a Cloudflare account, add your domain, and switch the nameservers at your registrar to the two Cloudflare provides. Create an A record for the apex and www pointing to the VPS IP, with the proxy switched on (orange cloud).
Confirm the records with the DNS Lookup tool once propagation finishes.
Step 2: get a certificate on the VPS for Cloudflare SSL
Pick one of two options:
- Let's Encrypt. Publicly trusted, valid 90 days today and 64 from 10 February 2027 (Let's Encrypt announcement), and it works if you ever turn the proxy off.
- Cloudflare Origin CA. Created in SSL/TLS, Origin Server. Trusted only by Cloudflare, so browsers will warn if someone bypasses the proxy.
Save the files on the server, for example:
sudo mkdir -p /etc/ssl/example
sudo nano /etc/ssl/example/fullchain.pem # paste certificate
sudo nano /etc/ssl/example/privkey.pem # paste private key
sudo chmod 600 /etc/ssl/example/privkey.pem
Before installing, open the certificate in the SSL/CSR Decoder to check the names it covers.
Step 3: Configure Nginx
server {
listen 443 ssl http2;
server_name example.com www.example.com;
ssl_certificate /etc/ssl/example/fullchain.pem;
ssl_certificate_key /etc/ssl/example/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
}
}
Run sudo nginx -t && sudo systemctl reload nginx. Apache users can do the same with SSLCertificateFile and SSLCertificateKeyFile in a port 443 virtual host.
Step 4: Turn on Full (strict)
In Cloudflare, open SSL/TLS, Overview and choose Full (strict). Enable Always Use HTTPS under Edge Certificates. If the origin certificate is invalid for the hostname you will see Error 526, which tells you strict mode is working.
Step 5: Limit access to Cloudflare
Cloudflare publishes its IP ranges at cloudflare.com/ips. Allow 443 only from those ranges and keep 22 restricted to your own address. With UFW the pattern looks like this:
sudo ufw default deny incoming
sudo ufw allow from 203.0.113.10 to any port 22 proto tcp # your IP, example value
# repeat for each range listed on cloudflare.com/ips
sudo ufw allow from <cloudflare-range> to any port 443 proto tcp
sudo ufw enable
Refresh the ranges from time to time, since Cloudflare can change them.
Verify Cloudflare SSL on the VPS
Run the domain through the SSL Checker, then the Security Headers checker to add HSTS and related headers. Test the redirect with the HTTPS Redirect checker.
Hardening notes
Disable password logins over SSH and use keys. Keep the operating system and web server patched. Turn on Authenticated Origin Pulls in Cloudflare if you want the origin to accept only requests that carry Cloudflare's client certificate, which is stronger than IP filtering alone. Keep backups of the origin certificate and key in a safe place, and start the renewal when a third of the lifetime is left if you use Let's Encrypt. Finally, do not publish the VPS IP in mail headers or DNS records that are not proxied.
Related reading: free SSL on nginx, Cloudflare Origin certificates, HTTPS for Cloudflare subdomains and SSL with Traefik.
Frequently Asked Questions
Do I need the Origin CA certificate or Let's Encrypt?
Either works with Full (strict). Use Let's Encrypt if you want the server to stay valid when the proxy is off. Use Origin CA with a long validity you choose on a proxied-only server, and track its expiry yourself, because Cloudflare sends no notices for origin certificates (Cloudflare Origin CA docs).
Why do I get Error 525 or 526?
525 means the TLS handshake with the origin failed, often because nothing listens on 443. 526 means the origin certificate is invalid for the hostname or expired.
Does Cloudflare hide my VPS IP?
It hides it for proxied records. Mail records, old DNS history, and any grey-cloud subdomain can still reveal it.
Is Flexible mode acceptable for a quick start?
Only as a stopgap. Traffic to the VPS is unencrypted, and it frequently causes redirect loops.
✅ Post-Installation Verification & SEO Checklist
After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:
- Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
- Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
- Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
- Confirm both root and
wwwversions resolve cleanly to one canonical HTTPS URL. - Verify your HTTPS property and
sitemap.xmlinside Google Search Console and Bing Webmaster Tools.