How to Block or Allow Traffic by Country in Cloudflare?
If you want to restrict access to your job board based on a visitor’s country—either to allow only traffic from specific countries or to block unwanted regions—Cloudflare provides an easy way to do this through its Web Application Firewall.
Important: Your domain must be connected to and proxied through Cloudflare for this to work. If you haven’t done this yet, follow this guide on Setting Up Cloudflare for Your Job Board’s Domain
Go to https://dash.cloudflare.com
Select the domain you want to configure.
In the left-hand sidebar, go to Security > WAF.
Click on the Custom Rules tab.
Click Create Rule.

Before setting up your rule, you’ll need the 2-letter ISO country codes for the countries you want to block or allow.
You can find the full list here: ISO 3166 Country Codes (Wikipedia)
Rule Name: Enter a descriptive name like Block Traffic from Canada.
Expression Editor: Click Edit expression and paste the following (replacing the country codes as needed):
ip.geoip.country in {"CA"}
Actions: From the dropdown, select Block.
Click Deploy to activate the rule.

Rule Name: Enter a descriptive name like Allow Only US and UK.
Expression Editor: Click Edit expression and paste:
not ip.geoip.country in {"US" "GB"}
Action: Select Block—this blocks all countries not listed.
Click Deploy.

Important: Your domain must be connected to and proxied through Cloudflare for this to work. If you haven’t done this yet, follow this guide on Setting Up Cloudflare for Your Job Board’s Domain
Step 1: Log in to Your Cloudflare Dashboard
Go to https://dash.cloudflare.com
Select the domain you want to configure.
Step 2: Navigate to Security Rules
In the left-hand sidebar, go to Security > WAF.
Click on the Custom Rules tab.
Click Create Rule.

Step 3: Create a Country-Based Rule
Before setting up your rule, you’ll need the 2-letter ISO country codes for the countries you want to block or allow.
You can find the full list here: ISO 3166 Country Codes (Wikipedia)
Option A: Block Traffic from Specific Countries
Rule Name: Enter a descriptive name like Block Traffic from Canada.
Expression Editor: Click Edit expression and paste the following (replacing the country codes as needed):
ip.geoip.country in {"CA"}
Actions: From the dropdown, select Block.
Click Deploy to activate the rule.

Option B: Allow Only Traffic from Specific Countries
Rule Name: Enter a descriptive name like Allow Only US and UK.
Expression Editor: Click Edit expression and paste:
not ip.geoip.country in {"US" "GB"}
Action: Select Block—this blocks all countries not listed.
Click Deploy.

Updated on: 14/05/2025
Thank you!