To restrict access to your website by country from Cloudflare for free, you must first login to your Cloudflare account or register if you are not a Cloudflare user:
Next, we will add our website by clicking on the 'Get Started' button:
We will specify the domain of our web site and click on continue
We will select the free plan, this plan includes the necessary restriction rules to block access by country:
danger The free plan can only be used with domains. Subdomains cannot be assigned to this type of plan.
Cloudflare will automatically scan your domain's DNS zone to pick up each DNS record and replicate the current zone on your servers.
If we see that any records are missing, we can add them in this step or edit the DNS zone later.
Finally, Cloudflare will ask us to change the Nameservers of our domain to point to them.
To change the Nameservers of your domain from SWPanel you can follow the manual "How to configure the DNS servers of my domain"
info The Nameservers change of a domain involves a global propagation process that can take up to 24/48 h depending on the domain extension.
Once the Nameservers change has been propagated globally, Cloudflare will send an email notifying that the service is now active.
From the dashboard of our service click on 'Security' -> 'WAF'.
We will create a new security rule:
We will have to perform three actions:
Assign a name to the rule.
In the section 'Field' we will choose 'Country' and in 'Value' the name of the country that we want that it does not accede to our site. In the case of wanting to block more than one country, we will click on the button 'or', to the right of the rule, to add another expression.
As action to perform in case the rules are met, we will select 'Block'.
Finally, using the 'Implement' button we will save and activate the rule.