Created
October 15, 2014 17:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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