Report this

What is the reason for this report?

Is it possible to block access to my website for specific country?

Posted on June 2, 2015

Are there any settings for docker to block access to my website for specific country?

Or I need to do all programming myself? Is it optimal to create a block in .htaccess?

Or which 3rd party services to use. Preferably free, of course.



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!

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.

Yes. You can use a firewall like iptables to block the IP address blocks associated with a country. This process is not 100% as any users using a VPN outside their country, using a service like TOR or a web proxy outside their country would still be able to access your server since they would not be assigned an IP address associated with their country.

I found this guide that should be helpful.

This references blocking Chinese IPs and the script near the bottom uses a third party service to source the IP lists. These can be found here.

Found a solution - I had Prestashop, and just wanted to block specific country. Appeared it is native setting in Preferences→Geolocation

Hello there,

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 comas:

CC_DENY = "AB,CD,EF"

You may find a list of ISO 3166-1 alpha-2 code at https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

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:

https://www.digitalocean.com/community/questions/how-to-install-and-configure-config-server-firewall-csf-on-centos

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.