Deny Access By Country - A Cloudflare Guide

Don’t want certain countries to access your website?Only want one or two to have the privilege? No matter your reason for restricting, this guide will help you out. I am assuming you already have Cloudflare setup on your website (Learn how to set Cloudflare up here), but not much other knowledge about the platform. Ready to get started?

The Cloudflare Firewall

If you read my beginners guide to Cloudflare, or you know your way around the platform, you already may know about the firewall. Cloudflare’s Firewall is an easy way for you to block, challenge, and allow different users based on pre-set criteria.

Country Restrictions

One of the features Cloudflare’s Firewall gives you is the ability to filter by country. Unfortunately, people can still get around these restrictions with a VPN, although you may be able to block some VPNs with Cloudflare if you wish. For example, you can block countries, allow them, or have visitors from certain countries complete a captcha before they visit your site. Once you are on the Firewall page (Firewall --> Firewall Rules), you can click the blue “Create A Firewall Rule” button to get started.

When you create a new rule, select “Country” for the first dropdown. In the second dropdown, select “equal” or “not equal” depending on what you want to do (If you want to block one country (Or a small number of countries), and allow all others, select “equal”. If you want to allow one country (Or a small number of countries), and block the rest, click “not equal”).

In the Value dropdown, select one of the countries you wish to either block or allow. Lastly, select either “Block” or “Allow” on the button dropdown depending on what you want to do. You will need to repeat this process for each country you wish to block or allow (When blocking or allowing multiple countries, make sure you click the “OR” button to add a statement, as it is impossible for your request to come from multiple countries at the same time).

In this example, I will block every country except for the US, Canada, and Mexico.

Cloudflare Firewall Example 1

Now, I will allow every country except for Australia to visit my site (Sorry Australia).

Cloudflare Firewall Example 2

If you want to block the TOR browser, you can do that as well!

Cloudflare Firewall Example 3 - Blocking TOR


The Cloudflare Firewall can take some time to get used to, but the features it holds are totally useful! If you want to learn more about the Firewall, be sure to check out the documentation. Be sure to check out the other things you can filter by (Besides Country), and you can have an amazing experience. See you next time!


Article Author

Related Articles

How to View Visitor and Request Logs with Cloudflare

Welcome! This article will show you how to view detailed logs on all your visitors (Both human and robot) using your Cloudflare account!


All code and content © 2024. Contact Us to learn more.