Skip to content
OCM LABS

How to run the 25 Cloudflare health checks for a Magento store

Run the 25 Cloudflare health checks for Magento from the admin or CLI, read the message, fix and evidence, and use the exit code as a deploy gate in CI.

Shane Blandford
Shane Blandford · FOUNDERPUBLISHED · 4 MIN READ

Most Cloudflare-in-front-of-Magento problems are one setting, and none of them show up in a Magento log. OCM Labs Cloudflare, the free and open source module, ships 25 health checks that read the zone, the Magento config and the live storefront and tell you what to change.

Where the checks live

  1. Open System > Cloudflare > Dashboard, pick the website and click the Health tab. Every check is listed with a status of pass, warn, fail or skip, a one-line fix and the evidence the check used.
  2. The checks run hourly from cron, at 15 minutes past the hour. Click Run checks now to run them on demand.
  3. Where a fix is a single zone setting, an Apply this fix button changes it from the admin. The button needs the OCMLabs_Cloudflare::settings_write ACL resource, so a role without it sees the result but not the button.

The same checks run from the command line:

bin/magento ocmlabs:cloudflare:health
bin/magento ocmlabs:cloudflare:health --website=base --json

Without --website the command runs for every website that has a zone configured. The plain form prints a table of status, check and message; --json prints the full results with status, message, fix and evidence per check. It exits 1 when any check fails, 2 on bad input, 0 otherwise. The full list is on the health checks docs page.

Connection (2 checks)

API TOKENThe token is valid and carries the permissions the module needs. Fix: create a new token with the permissions listed on the Installation page.
ZONE MATCHES STOREFRONTThe configured zone's name matches the website's storefront hosts. Catches a Zone ID pasted from the wrong zone.

If either fails, fix it first; everything below depends on it.

Zone settings (7 checks)

These are Cloudflare settings that break Magento or make caching pointless. Each one shows the current value and offers an Apply this fix button.

SSL MODEFull or Full (strict). Flexible makes Cloudflare talk HTTP to the origin, which loops with Magento's secure base URL.
ROCKET LOADEROff. It rewrites script loading and breaks RequireJS on Luma and Alpine.js on Hyva.
AUTO MINIFYOff on zones that still have it. Magento minifies its own assets, and Cloudflare's minifier can break RequireJS modules and Alpine expressions.
EMAIL OBFUSCATIONOff. It rewrites addresses inside rendered HTML and injects a script into cached pages.
ALWAYS ONLINEOff. It serves stale prices and stock from the Internet Archive when the origin is down.
BROTLI, HTTP/2, HTTP/3 AND EARLY HINTSOn. Warns about each one that is off; none of them breaks Magento, they just make it faster.
BROWSER CACHE TTLRespect Existing Headers. Any override replaces the module's max-age=0 and keeps purged pages alive in visitors' browsers.

Cache rules (5 checks)

STOREFRONT CACHE RULEA [OCMLabs] Cache storefront HTML rule exists for the website's hosts.
BYPASS RULESThe bypass rules exist and sit below the cache rule, so they override it.
X-MAGENTO-VARY HANDLINGThe vary cookie is handled, either by the bypass rule or by a custom cache key on an Enterprise zone. Fix: apply the recommended cache rules.
NO POST CACHINGA rule bypasses non-GET requests.
EDGE TTLThe TTL the cache rule applies matches the module's edge TTL. Warns when a rule overrides the origin TTL.

The fix for most of this group is the same: apply the recommended rules, from the Health tab or with bin/magento ocmlabs:cloudflare:rules:apply. Post 4 covers the six rules, the diff and writing them by hand.

Magento (6 checks)

CLOUDFLARE CACHE TYPEThe ocmlabs_cloudflare cache type is enabled under System > Cache Management. The module stores zone details, analytics and health results in it.
EDGE CACHE ENABLEDEnable Edge Caching of HTML is on for the website. Warns, rather than fails, because leaving it off is a valid choice.
PURGE QUEUE CONSUMERCompares the last cache clean event with the last completed purge. Warns when tags are queued but nothing has gone out, which usually means the consumer is not running.
STOREFRONT THEMEDetects Luma or Hyva for the website's stores and notes which Cloudflare features would break it.
MULTI-STORE EDGE CACHINGLists the website's store views and currencies and explains that visitors outside the default context bypass the edge unless Vary Handling is Cache key on an Enterprise zone.
REAL VISITOR IPWhether the current admin request's REMOTE_ADDR was a Cloudflare address and CF-Connecting-IP was honored. Only meaningful from an admin request that came through Cloudflare; skipped from the CLI.

Real visitor IP inspects the admin request you just made. From bin/magento there is no Cloudflare request to inspect, so it reports skip. Click Run checks now from an admin session that came through Cloudflare to get an answer.

Live probes (5 checks)

The probes fetch real storefront pages through Cloudflare and read cf-cache-status. They request a category page twice and expect the second to be a HIT, request a customer page and expect BYPASS or DYNAMIC, and send the vary cookie and expect the edge to step aside. Probe URLs come from the website's own catalog, and a probe refuses to fetch anything that does not resolve to the configured storefront hosts.

EDGE CACHES A STOREFRONT PAGEA category page served through Cloudflare reports cf-cache-status: HIT on the second request.
EDGE BYPASSES CUSTOMER AND CHECKOUT PAGESThe login page reports BYPASS or DYNAMIC, never HIT.
EDGE HANDLES THE VARY COOKIEA request carrying X-Magento-Vary is not served from the edge cache.
ORIGIN SENDS EDGE CACHE HEADERSFetches the page directly from Storefront Origin, skipping Cloudflare, and checks that Cache-Control and Cache-Tag arrive intact. Fails when a proxy or Varnish between Magento and Cloudflare strips them. Skipped when Storefront Origin is blank.
CACHE-TAG HEADER SIZESamples storefront responses and reports pages whose tag list had to be truncated to fit Cloudflare's header limits, with the paths involved. Those pages still purge on a full purge but may miss a tag purge.

The origin probe only runs when Storefront Origin is set, so a skip on that row means the field is blank. TLS certificate verification is skipped for that fetch, because origin certificates are rarely valid for the public host. Each probe needs the page to answer with HTTP 200; a redirect or error is reported as a failed probe with the status it got.

Reading a result

Every result carries three things:

  • Message: what was found.
  • Fix: what to change, and where in the Cloudflare dashboard.
  • Evidence: the raw values the check looked at, such as the setting value or the response headers.

When you open a support issue, attach bin/magento ocmlabs:cloudflare:health --json, which includes all three for every check. To see by hand what the origin probe sees:

curl -sI -H "Host: www.example.com" https://<origin ip>/some-category.html -k | grep -iE "cache-control|cache-tag"

You should get Cache-Control: public, max-age=0, s-maxage=... and a Cache-Tag line.

Using the command as a deploy gate

Because the command exits 1 on any failed check, it slots in as the last step of a deploy, after the rules are applied and the cache is purged:

#!/usr/bin/env bash
set -euo pipefail

bin/magento ocmlabs:cloudflare:rules:apply
bin/magento ocmlabs:cloudflare:purge --all

if ! bin/magento ocmlabs:cloudflare:health --website=base --json > var/log/cloudflare-health.json; then
  echo "Cloudflare health checks failed:" >&2
  cat var/log/cloudflare-health.json >&2
  exit 1
fi

Two limits. Warns do not fail the command, so a stopped purge consumer will not block a deploy; only fails do. And Real visitor IP is always skip from the CLI, so the gate cannot catch a wrong CF-Connecting-IP setup. The same JSON feeds a monitor: run it on a schedule and alert on any fail.

Which checks to look at first

CF-CACHE-STATUS: DYNAMIC ON EVERY PAGEEdge cache enabled, Storefront cache rule, then Origin sends edge cache headers if Varnish or a proxy sits in between.
PAGES ARE STALE AFTER A PRODUCT SAVEPurge queue consumer, then Browser Cache TTL. If curl is fresh and the browser is stale, the TTL override is the cause.
CHECKOUT, CART OR ACCOUNT PAGES WERE CACHEDEdge bypasses customer and checkout pages. A Cache Everything rule, a page rule or an edge TTL override overrode Magento's headers. Remove it and purge everything.
REDIRECT LOOP ON THE STOREFRONTSSL mode. Flexible is the cause; the check offers to set Full or Full (strict).
JAVASCRIPT IS BROKEN ON THE STOREFRONTRocket Loader and Auto Minify. Both rewrite the page.

For the DYNAMIC case, the settings that make a page cacheable are in post 2. One cause no check finds: a block with cacheable="false" in the layout makes the whole page uncacheable. Search the theme and extensions for it.

If you want someone to run the checks against your stack and fix what fails, our performance and infrastructure team does this for Magento stores behind Cloudflare.

FAQ

How often do the Cloudflare health checks run in Magento?+
Hourly from cron, at 15 minutes past the hour. You can also run them on demand from the Health tab with Run checks now, or from the command line with the health command.
What does the health command exit code mean?+
0 when every check passes or warns, 1 when any check fails, and 2 on bad input such as an invalid option. Warnings never block a deploy on their own.
Why is the Real visitor IP check skipped from the CLI?+
It inspects the admin request that triggered it, and a command line run has no Cloudflare request to inspect. Run it from an admin session that came through Cloudflare.
Why is the Origin sends edge cache headers probe skipped?+
It fetches the page directly from the Storefront Origin setting, skipping Cloudflare. When that field is blank the probe has nothing to fetch. Fill it in and run the checks again.
Can the live probes fetch pages from another site?+
No. Probe URLs come from the website's own catalog, and a probe refuses to fetch anything that does not resolve to the configured storefront hosts.
What should I attach to a support issue?+
The JSON output of the health command, which includes the status, message, fix and evidence for every check. With Debug Logging on, the relevant lines from the module's log file help too; the token is redacted there.
Shane Blandford

Shane Blandford

FOUNDER

Founder of Orange Collar Media, a Denver ecommerce agency behind 800+ Magento and Shopify builds. In Magento since version 1.x - building, rescuing, and supporting revenue-critical stores since 2008.

All posts by Shane Blandford→

KEEP READING

Related from the Journal.

Your store can sell more. Let's find out how much.

Start a project