I have a client that wanted to limit traffic to their site to only come from the US.
Right away I told them we could use a module in nginx that uses the maxmind geoip library.
It turns out I was right nginx does have a geoip module!
Lucky for me.
Anyway it turns out that using the module is really simple.
After installing it I simply told nginx to route all requests from the US to unicorn and the rest get redirected.
# send US traffic to unicorn
if ($geoip_country_code = US) {
proxy_pass http://unicorn;
break;
}
# all other traffic gets redirected
rewrite ^(.*) http://foosite.com$1 permanent;
BTW yes hacksors their are a lot of ways of getting around this I know but it should be effective for most requests.