Skip to content

Instantly share code, notes, and snippets.

@davewalk
Created October 15, 2014 17:50
Show Gist options
  • Save davewalk/64a6621db86adc8ebb75 to your computer and use it in GitHub Desktop.
Save davewalk/64a6621db86adc8ebb75 to your computer and use it in GitHub Desktop.
Allow access to your stuff from a U.S. IP or a local IP (you know, for a load balancer or something) in Nginx
geoip_country /usr/share/GeoIP/GeoIP.dat;
map $geoip_country_code $allowed_country {
default no;
US yes;
}
geo $inNet {
default no;
10.0.0.0/8 yes;
}
# Keep in mind that Nginx doesn't allow compound or nested IF statements (http://wiki.nginx.org/IfIsEvil)
server {
if ($inNet = no) {
set $allowed N;
}
if ($allowed_country = no) {
set $allowed "${allowed}N";
}
if ($allowed = NN) {
return 444;
}
# Go ahead and serve at this point
}
# Thx to: https://gist.github.com/jrom/1760790
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment