Block countries from accessing my website

Hello. Can you help me block specific countries from accessing my website.

Thank you.


Chris Anthony

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hello there,

You can use CSF in order to block a country, you can use the CC_DENY option which accepts two-letter country codes such as US, GB and etc.

In order to list more than one country you just need to separate them using commas:


You may find a list of ISO 3166-1 alpha-2 code at

If you’re not familiar with CSF or you want to install it on CentOS or Ubuntu droplet check out this mini tutorial:

For CentOS:

For Ubuntu:

Hope that this helps!

I recommend you setting up your website with Cloudflare, I believe that they have a feature that allows you to block certain countries from accessing your website.

How detailed do you want the list. If you want to do mass blocking you could use

For instance if you want to block all APNIC (Asia Pacific ips) firewall off all the APNIC /8 entries. lets you do it by country but that take a lot of time to compile a list unless you are targeting only a couple countries.

Of course they could always use a proxy to bypass this.