Sites behind Cloudflare

Add a Cloudflare API token, create a site’s DNS records, install an Origin certificate, and accept connections only from Cloudflare.

5-minute read Applies to XenoPanel 1.0.0 Updated

XenoPanel talks to Cloudflare’s API from your Mac, never from the server. It can create a site’s DNS records, install a Cloudflare Origin certificate on the server, and make a site accept connections only from Cloudflare.

Add a token

In Cloudflare’s dashboard, create an API token with Zone Read, DNS Edit and SSL and Certificates Edit on the zones XenoPanel will manage. Then:

Terminal
$ xenopanel cloudflare token add main
$ xenopanel cloudflare token list  # each token and the zones it reached

You type the token at a hidden prompt, or pipe it in with --token-stdin; it’s never part of the command. XenoPanel checks it and keeps it in your Mac’s Keychain.

A token can cover every domain in your Cloudflare account, or a single client’s domain, and both kinds work side by side. When you don’t name a token, XenoPanel uses the one that reaches the site’s domain. After adding a domain to an account, xenopanel cloudflare token refresh reads again which zones each token reaches.

Set a site up at Cloudflare

The quickest way is when you add the site:

Terminal
$ xenopanel site add example.com --client acme --cloudflare --cloudflare-only

For a site you already have, run the steps one at a time:

Terminal
$ xenopanel dns status example.com  # what would change; changes nothing
$ xenopanel dns apply example.com --www
$ xenopanel cert issue example.com
$ xenopanel site cloudflare-only example.com on
  • DNS: dns apply creates the site’s A and AAAA records, pointing at the server and proxied through Cloudflare. --www adds www too, and --no-proxy makes them DNS only. Changing or deleting a record that’s already there needs --confirm example.com.
  • Certificate: cert issue gets a 15-year Cloudflare Origin certificate for the domain and its subdomains and installs it in the site’s vhost. A site that already has one keeps it unless you add --renew. Origin certificates are trusted by Cloudflare, not by browsers, so they go with proxied records.
  • Cloudflare only: with it on, the site’s vhost refuses connections that don’t come from Cloudflare. It’s set per site, in the vhost; the firewall stays open on 80 and 443 for every site.

The server’s nginx logs show each visitor’s own address, not Cloudflare’s. xenopanel server update web-1 --cloudflare refreshes Cloudflare’s address ranges when they change.

Add a new domain to Cloudflare

Terminal
$ xenopanel cloudflare zone add example.org
$ xenopanel cloudflare zone status example.org  # active yet?

This needs a token with Zone Edit on the whole account. The domain joins the account on Cloudflare’s Free plan, its current DNS records are imported, and XenoPanel shows the two name servers to set at your registrar. Nothing changes for visitors until you do.

Removing a token

xenopanel cloudflare token remove main takes the token out of your Keychain. It keeps working at Cloudflare until you delete it there.

Questions about XenoPanel?

Check the help pages first, or send us a message and we’ll get back to you within 24 hours.

Need help with an app or a license? Open a support ticket →

We reply within 24 hours on business days.