Supported CDN country headers
If your site sits behind a CDN or proxy, the CDN can tell Shield which country each visitor is in. This is the best way to run geo-blocking: it’s instant, free, and needs no outside lookup service.
This topic lists the headers Shield reads, how it picks between them, and how to make your CDN send one.
How Shield reads the headers#
Shield looks at six headers, in this order, and stops at the first valid one:
| Order | Header | Normally sent by |
|---|---|---|
| 1 | CF-IPCountry | Cloudflare |
| 2 | CDN-Country | Bunny.net |
| 3 | CloudFront-Viewer-Country | AWS CloudFront |
| 4 | X-Vercel-IP-Country | Vercel |
| 5 | X-Country-Code | Fastly, Akamai, or a custom setup |
| 6 | X-Geo-Country | A generic reverse proxy or your own config |
A header counts as valid only if it holds exactly two letters, such as US or DE. Anything else is skipped. That includes empty values, the XX value (Cloudflare’s “unknown country” code) and codes with numbers in them. When a header is skipped, Shield tries the next one. If none is valid, Shield uses the IP lookup service you chose, then the Fallback setting. “How geo-blocking works” explains that part.

Turning header detection on or off#
On the Geo tab, the Trust CDN geo headers switch controls whether Shield looks at these headers at all.
- On: Shield reads the headers first and only uses the lookup service if it finds none.
- Off: Shield ignores the headers completely and goes straight to the lookup service.
Turn it on only when your site really is behind a CDN or proxy that sets these headers. If it isn’t, anyone can send a fake header like CF-IPCountry: US with their request and pretend to be in an allowed country. A CDN replaces or removes such a header before it reaches your server, but a direct connection to your server doesn’t.
Make your CDN send the header#
Each CDN has its own setting. Check your provider’s current documentation, since these settings move around.
Cloudflare. Cloudflare adds CF-IPCountry to requests when its IP geolocation feature is enabled for your site. Look for it in your Cloudflare dashboard’s network settings. Cloudflare marks unknown countries as XX, which Shield ignores.
Bunny.net. Bunny can pass the visitor’s country to your origin as a request header. Check Bunny’s documentation for the exact header name your CDN zone sends and compare it with the table above.
AWS CloudFront. CloudFront doesn’t send the country to your origin by default. You must add the CloudFront-Viewer-Country header to the origin request policy attached to your distribution.
Vercel. Vercel adds X-Vercel-IP-Country to requests on its platform.
Fastly, Akamai and other proxies. These don’t send a country header by default. You can add one in your CDN’s configuration and name it X-Country-Code or X-Geo-Country. Both are names Shield already checks.
Nginx or a server-level geo module. If your server or hosting provider knows the visitor’s country, it may let you pass it on as X-Geo-Country. Ask your host.
If your CDN uses a different header#
If your CDN sends the country in a header with another name, configure the CDN to also send it as X-Geo-Country (or X-Country-Code). Shield only reads the six headers in the table.
Don’t mix this up with the visitor’s IP address#
Country headers and the visitor’s IP address are separate things.
- Trust CDN geo headers (Geo tab) tells Shield where the visitor is.
- Trust proxy headers (Lockout tab) tells Shield which IP address the visitor has, which matters for lockouts and the blocklist.
Behind a CDN you usually need both. Without Trust proxy headers, Shield can see your CDN’s IP instead of the visitor’s, and lockouts and the blocklist won’t work as expected. See “Lockouts are keyed to the wrong IP (proxies and CDNs)” in the Troubleshooting section.
How to check that it’s working#
- Turn on Trust CDN geo headers and save.
- Block a country you can test from, such as one a VPN or a colleague abroad can use, and keep your own IP whitelisted so you can’t lock yourself out.
- Open your login page from that country. You should see the “Access restricted” screen.
- Check the Log tab for the Geo block entry.
If the test visitor still sees the login form, the usual causes are:
- The CDN isn’t sending a header, or sends one Shield doesn’t read.
- The page was served from a cache and never reached your server. See “Caching and login pages” in the Troubleshooting section.
- The country isn’t on your list, or Use a custom list at login isn’t selected.
Was this helpful?
Thanks for your feedback!
✓ Feedback received. Thank you!