Skip to content

Instantly share code, notes, and snippets.

@teebow1e
Forked from Bara/ccf.md
Last active May 30, 2025 17:49
Show Gist options
  • Save teebow1e/c02b8e3e79506f252662762118bcbcb0 to your computer and use it in GitHub Desktop.
Save teebow1e/c02b8e3e79506f252662762118bcbcb0 to your computer and use it in GitHub Desktop.
[Selfhost] Caddy with Cloudflare Proxy

Create API Key on Github

  • My Profile
  • API Tokens
  • Create Token
  • Edit zone DNS (Template)
  • Change permissions from Edit to Read (I tested this with Edit)
  • Add your domains/zones under Zone Resource
  • Add your IPv(4/6) under Client IP Adress Filtering
  • Click on Continue to summary
  • Click on Create Token
  • Copy your Key

Set SSL/TLS encryption mode to Full (strict)

Add your (Sub-)Domain record with enabled Proxy status

Add the following part into your Caddyfile for your (Sub-)Domain:

    tls {
        dns cloudflare <api_key>
    }

// Credits: https://samjmck.com/en/blog/using-caddy-with-cloudflare/

or (for linux) set env value like this:

echo "export CLOUDFLARE_AUTH_TOKEN=TOKEN_HERE" >> ~/.bashrc
source ~/.bashrc

and you can use this in caddy:

    tls {
        dns cloudflare {env.CLOUDFLARE_AUTH_TOKEN}
    }

If you get this error on startup: module not registered: dns.providers.cloudflare

Download (and replace your currently binary file) a custom version on https://caddyserver.com/download with caddy-dns/cloudflare as feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment