This guide shows how to set up your domain with Cloudflare so you can use DNS automation in StackPilot.
- IPv4/IPv6 translation - If your VPS only has an IPv6 address, Cloudflare acts as a proxy so IPv4-only clients can still reach it.
- DNS automation - The
dns-add.shscript automatically adds DNS records via the Cloudflare API. - Free SSL - Cloudflare provides SSL certificates with no configuration needed.
- DDoS protection - Free basic protection against attacks.
- CDN - Faster page loading for users worldwide.
If you do not have a domain yet, purchase one from any domain registrar (Namecheap, Porkbun, Google Domains, GoDaddy, OVH, etc.).
Choose a registrar with fair renewal prices. Many registrars offer cheap first-year pricing but charge significantly more on renewal.
- Go to cloudflare.com and click "Sign Up"
- Enter your email and password
- Choose the Free plan
The free plan is genuinely sufficient:
- Unlimited number of domains
- Full API for DNS automation
- SSL/HTTPS for all domains
- CDN and DDoS protection
- No traffic limits
Paid plans ($20+/month) are for large businesses with millions of visitors. For a VPS and small business, Free = everything you need.
- After logging in, click "Add a Site"
- Enter your domain (e.g.
example.com) - withoutwww! - Choose the Free plan
- Cloudflare will scan existing DNS records
Cloudflare will show you two nameservers, for example:
aria.ns.cloudflare.com
brett.ns.cloudflare.com
Now set these at your domain registrar:
- Log in to your registrar's control panel
- Navigate to your domain's DNS settings
- Change the nameservers to the ones Cloudflare provided
- Save changes
Note: Nameserver changes can take up to 24-48 hours to propagate, but usually work within 1-2 hours.
- Go back to Cloudflare
- Click "Check nameservers"
- Once the nameservers propagate, you will see status "Active"
- In Cloudflare, go to SSL/TLS -> Overview
- Set the mode to "Full" (not "Flexible"!)
Important: The "Flexible" mode can cause redirect loops with Caddy. Use "Full".
Now you can set up automatic DNS record management:
cd stackpilot
./local/setup-cloudflare.shThe script will:
- Open your browser to the Cloudflare API token creation page
- Create a token with "Edit zone DNS" permission
- Paste the token in the terminal
- Done!
Adding a domain is now a single command:
# Add a DNS record (IPv6 is fetched automatically!)
./local/dns-add.sh status.example.com vps
# Expose an application via HTTPS
ssh vps 'sp-expose status.example.com 3001'Check whether the domain works:
# Check DNS
ping status.example.com
# Check HTTPS
curl -I https://status.example.comWait 5-10 minutes. Cloudflare is fast, but propagation can take a moment.
- Verify that Cloudflare SSL mode is set to "Full" (not "Flexible")
- Check that the proxy is enabled (orange cloud icon next to the DNS record)
- Check that the application is running:
ssh vps 'docker ps' - Check that the port is correct in
sp-expose
- Make sure Caddy is installed:
ssh vps 'which caddy' - Check Caddy status:
ssh vps 'systemctl status caddy'
You can also transfer your entire domain to Cloudflare Registrar - this keeps everything in one place and is often cheaper. The option is available under Cloudflare -> Domain Registration -> Transfer Domains.