GeoIP blocking countries using Nginx
Quick and easy way to block entire countries using simple nginx rules. Note this is for Ubuntu/Nginx but may work on other systems.
Install required packages & add to nginx config.
The GeoIP DB will be under /usr/shared/GeoIP/GeoIPv6.dat (Or GeoIP.dat for v4 only):
|
|
Add this block under the main “http” block in nginx.conf:
|
|
Then we need to add a simple check in our site vhost inside the server {
block, but before the location /
block:
|
|
Quick reload and boom! Done!
|
|
Based off an older gist found on Github here