Easily implement country blocking in Cloudflare free

(Update 19 July 2019 – updated to reflect correct boolean logic for multiple countries)

Cloudflare is an amazing web-based security and performance improvement product for website admins. If you’re running Cloudflare, even on the free version, and are looking at blocking access from countries using a whitelist-only approach, look no further.

  1. Log into your Cloudflare account.
  2. Navigate to the “Firewall” , click on “Firewall Rules“, then click on “Create a Firewall rule.”
  3. For one country: In the “Rule name” section, give your rule a descriptive name. Under “Field” select “Country“, under “Operator” select “does not equal“, under “Value” select your country that you want to allow, select “Block” under “Choose an action“, and finally click on “Deploy.”
  4. For multiple countries: change the “Operator” to “is not in” and list multiple countries in the “Value” field.

  5. Ensure that your rule is at the top of your list if you have multiple rules. Cloudflare processes rules in the order that they are listed.
  6. Lastly check your rule by visiting your site from a country that is not in your allow list. You should get a block message.

Leave a Reply

Your email address will not be published. Required fields are marked *

5 × 5 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.