# Geo blocking, but allowing google index robot to pass-thru

**URL:** <https://www.ruby-forum.com/t/geo-blocking-but-allowing-google-index-robot-to-pass-thru/226688>\
**Category:** NGINX\
**Created:** [February 18, 2013, 1:01pm UTC](https://www.ruby-forum.com/t/geo-blocking-but-allowing-google-index-robot-to-pass-thru/226688 "2013-02-18T13:01:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 18, 2013, 1:01pm UTC](https://www.ruby-forum.com/t/geo-blocking-but-allowing-google-index-robot-to-pass-thru/226688/1 "2013-02-18T13:01:44Z")

</div>

Hi

I have a site where i want to geo block all but one country, but perhaps  
allow Google to index site, perhaps some other index bot too.

So what sort of configuration is needed so i can detect Google bot and  
let  
it pass-thru? Would be nice if there is example configuration. Is only  
good way to check user-agent?

Pekka Panula | Jatkuvat Palvelut | Direct +358 10 235 9232 |  
removed\_email\_address@domain.invalid  
Sofor Oy | [www.sofor.fi](http://www.sofor.fi) | Takakaarre 3 | PL 51 | FIN-62200 Kauhava  
tel. +358 10 235 90 | fax +358 10 235 9100

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 18, 2013, 10:11pm UTC](https://www.ruby-forum.com/t/geo-blocking-but-allowing-google-index-robot-to-pass-thru/226688/2 "2013-02-18T22:11:51Z")

</div>

On Mon, 2013-02-18 at 14:00 +0200, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Pekka Panula | Jatkuvat Palvelut | Direct +358 10 235 9232 |  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> Sofor Oy | www.sofor.fi| Takakaarre 3 | PL 51 | FIN-62200 Kauhava  
> tel. +358 10 235 90 | fax +358 10 235 9100

Here’s some code I use for a similar setup…

map $geoip\_country\_code $external\_redirects {  
default ‘Block’;

US [http://www.example.com](http://www.example.com);  
}

#Whitelist crawlers  
map $http\_user\_agent $crawler {  
default 0;

~\*(AdsBot-Google|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|  
bingbot|Feedfetcher-Google|Googlebot|Yahoo\ !Slurp|msnbot|msnbot-media|  
YahooCacheSystem) 1;  
}

# You’ll also probably need to override for specific IP addresses too…

geo $whitelisted {  
default $crawler;

# localhost

127.0.0.0/8 1;

# CloudFlare

204.93.240.0/24 1;  
204.93.177.0/24 1;  
199.27.128.0/21 1;  
173.245.48.0/20 1;  
103.21.244.0/22 1;  
103.22.200.0/22 1;  
103.31.4.0/22 1;  
141.101.64.0/18 1;  
108.162.192.0/18 1;  
190.93.240.0/20 1;  
188.114.96.0/20 1;  
197.234.240.0/22 1;  
198.41.128.0/17 1;  
}

You can then use your own logic with the values of $external\_redirects  
and $whitelisted to control redirections.

hth,

Steve
