TEXT   218
Use GeoIP database to restrict access to the site by country
Guest on 28th November 2024 07:13:00 AM


  1. http {
  2.         # .......... a lot of stuff .........
  3.  
  4.         # Use GeoIP database to restrict access to the site by country:
  5.         geoip_country /usr/share/GeoIP/GeoIP.dat;
  6.  
  7.         # Access is blocked by default and only allowed to visitors from Ukraine
  8.         # (useful agains DDoS attacks from Asian and Western European botnets):
  9.         map $geoip_country_code $allowed_country {
  10.             default no;
  11.             UA yes;
  12.         }
  13.  
  14.         server {
  15.                 # .......... a lot of stuff .........
  16.                 # Actually block access from countries famous for hosting botnets:
  17.                 if ($allowed_country = no) {
  18.                      return 444;
  19.                 }
  20.                 # .......... a lot of other stuff .........
  21.         }
  22. }

Raw Paste

Login or Register to edit or fork this paste. It's free.