Articles on: Localization

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

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.

Creating Custom Rule On Cloudflare

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

Was this article helpful?

Share your feedback

Cancel

Thank you!