Report this

What is the reason for this report?

Block Some Countries from visiting my website

Posted on October 16, 2014

I’m currently using NginX on my Server and i want to block some countries from visiting my website. Can anyone help me please?



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.

Hi all, I used this method to block access to /wp-admin location from all countries except some preferred.

location /wp-admin {
    if ($allowed_country = no) {
        return 403;
    }
}

It works fine when trying to open this page in browser. But still I can see in access.log many POST requests and in worpdress logs failed login requests from rejected countries. Is possible to use geoip-database-contrib module also for POST requests?

I tried:

location /wp-admin {
    if ($allowed_country = no) {
        deny all;
    }
}

but after reload nginx doesnt start at all. Do you have any ideas?

Your site is exactly what I have looking for!! It certainly helps a frequent traveler like me to locate all the stamp shows when traveling. Keep up with the good work.

This comment has been deleted

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.