# GeoIp local countries

**URL:** <https://www.ruby-forum.com/t/geoip-local-countries/194582>\
**Category:** NGINX\
**Created:** [September 7, 2010, 1:39pm UTC](https://www.ruby-forum.com/t/geoip-local-countries/194582 "2010-09-07T13:39:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![soisita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9e8a1a/32.png) [@soisita](https://www.ruby-forum.com/u/soisita)\
**Post date:** [September 7, 2010, 1:39pm UTC](https://www.ruby-forum.com/t/geoip-local-countries/194582/1 "2010-09-07T13:39:14Z")

</div>

Hi,  
I’m new here and uses nginx for a couple of months as a reverse proxy  
for apache since I discovered this server (setup for magento website)  
I now need to localize my users, meaning redirecting german users to  
[domain.de](http://domain.de), us ones to [domain.com](http://domain.com), french ones to [domain.fr](http://domain.fr), etc, and all  
others to .com

As I’m running debian servers, I’ve upgraded nginx from 0.6.32 to 0.7.67  
–with-http\_geoip\_module  
I have a config file for each of my local domains in sites-avalaible /  
sites-enabled with both config for 80 & 443 ports in “server” directive

[domain.com](http://domain.com) :

```auto
server {
        listen 80;
        server_name domain.com;
        bla bla
        location / {
              proxy_pass http://.......
        }
server {
        listen 443;
        server_name domain.com;
        bla bla
        location / {
              proxy_pass https://.......
        }
}
```

I wonder how and where to put the directives like :

```auto
if ($geoip_country_code = FR) {
rewrite ^(.*)$ http://domain.fr$1 permanent;
}
if ($geoip_country_code = DE) {
rewrite ^(.*)$ http://domain.de$1 permanent;
}
...
```

as I would like not to write those in each vhost in order for  
maintenance to remain efficient and as I would like to avoid redirection  
loops…  
I tried to put them directly in conf.d/geo.conf but it seems they have  
to be under a server directive…

Any idea ?  
Thanks in advance for your help

Best

Posted at Nginx Forum:

> **[GeoIp local countries](https://forum.nginx.org/read.php?2,127911,127911#msg-127911)**
>
> Hi, I'm new here and uses nginx for a couple of months as a reverse proxy for apache since I discovered this server (setup for magento website) I now need to localize my users, meaning redirecting german users to domain.de, us ones to domain.com,...

---

<div class="post-metadata">

**Author:** ![soisita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9e8a1a/32.png) [@soisita](https://www.ruby-forum.com/u/soisita)\
**Post date:** [September 7, 2010, 5:11pm UTC](https://www.ruby-forum.com/t/geoip-local-countries/194582/2 "2010-09-07T17:11:47Z")

</div>

Testing in [domain.fr](http://domain.fr) vhost file

```auto
if ($geoip_country_code = FR) {
rewrite ^(.*)$ http://domain.de$1 permanent;
break;
}
```

while being in France (to see if geoip rules), I fall in a loop,  
redirecting to [domain.de](http://domain.de) (so I assume this part is ok), then asking for  
[domain.fr](http://domain.fr) again , etc.

Where am I wrong ?

Tks

Posted at Nginx Forum:

> **[Re: GeoIp local countries](https://forum.nginx.org/read.php?2,127911,127997#msg-127997)**
>
> Hi, I'm new here and uses nginx for a couple of months as a reverse proxy for apache since I discovered this server (setup for magento website) I now need to localize my users, meaning redirecting german users to domain.de, us ones to domain.com,...
