# Nginx load balancer with GeoIP

**URL:** <https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014>\
**Category:** NGINX\
**Created:** [November 11, 2008, 4:19am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014 "2008-11-11T04:19:57Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glen\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@Glen\_L](https://www.ruby-forum.com/u/Glen_L)\
**Post date:** [November 11, 2008, 4:19am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014/1 "2008-11-11T04:19:57Z")

</div>

Hi there,

Is nginx will support load balancing with GeoIP support?

Example :

If match country US

```
            Proxy_pass http://us.server/;

```

If match other

```
            Proxy_pass http://default.server/;

```

Regards,

Glen L.

---

<div class="post-metadata">

**Author:** ![Glen\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@Glen\_L](https://www.ruby-forum.com/u/Glen_L)\
**Post date:** [November 11, 2008, 7:48am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014/2 "2008-11-11T07:48:07Z")

</div>

On Tue, Nov 11, 2008 at 10:10:42AM +0700, Glen L. wrote:

> If match other
> 
> ```
> Proxy_pass http://default.server/;
> 
> ```

http {  
geo $geo {  
default default;  
1.1.1.0/24 us;  
1.1.2.0/24 us;  
1.1.3.0/24 us;  
…  
}

```
  upstream us.server {
      ....
  }

  upstream default.server {
      ....
  }

  server {
       location / {
           proxy_pass http://$geo.server;
       }

```

---

<div class="post-metadata">

**Author:** ![Glen\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@Glen\_L](https://www.ruby-forum.com/u/Glen_L)\
**Post date:** [November 11, 2008, 8:26am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014/3 "2008-11-11T08:26:48Z")

</div>

How do I spread connection if I use  
./geo2nginx.pl GeoIPCountryWhois.csv \> geo.conf

Regards,

Glen L.

---

<div class="post-metadata">

**Author:** ![Glen\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@Glen\_L](https://www.ruby-forum.com/u/Glen_L)\
**Post date:** [November 12, 2008, 8:42am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014/4 "2008-11-12T08:42:22Z")

</div>

If our protocol is RTSP which is using port 554, is that posibble to  
load  
balancing with nginx?  
If yes, how can I do it? Because I got 400 Error (Bad Request) on  
access.log

Regards,

Glen L.

---

<div class="post-metadata">

**Author:** ![Glen\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@Glen\_L](https://www.ruby-forum.com/u/Glen_L)\
**Post date:** [November 12, 2008, 8:56am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014/5 "2008-11-12T08:56:25Z")

</div>

When using it for HTTP request, it show me error on my browser

Bad Request

Your browser sent a request that this server could not understand.

Here’s my configuration

```
geo $geo {
    default default;
include geo.conf;
}

upstream ID.server {
    server 10.50.12.123;
}

upstream default.server {
    server 1.2.3.4;
}

```

server {  
listen 10.50.12.134:80;

```
location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_pass http://$geo.server;

```

Anyone know how to fix this?

Regards,

Glen L.

---

<div class="post-metadata">

**Author:** ![Glen\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@Glen\_L](https://www.ruby-forum.com/u/Glen_L)\
**Post date:** [November 12, 2008, 9:29am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014/6 "2008-11-12T09:29:49Z")

</div>

On Wed, Nov 12, 2008 at 02:35:03PM +0700, Glen L. wrote:

> If our protocol is RTSP which is using port 554, is that posibble to load  
> balancing with nginx?  
> If yes, how can I do it? Because I got 400 Error (Bad Request) on access.log

No, only HTTP is supported.

---

<div class="post-metadata">

**Author:** ![Glen\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@Glen\_L](https://www.ruby-forum.com/u/Glen_L)\
**Post date:** [November 12, 2008, 9:30am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014/7 "2008-11-12T09:30:24Z")

</div>

On Wed, Nov 12, 2008 at 02:49:10PM +0700, Glen L. wrote:

> ```
> include geo.conf;
> 
> ```
> 
> server {  
> listen 10.50.12.134:80;
> 
> ```
> location / {
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> proxy_set_header Host $host;
> proxy_pass http://$geo.server;
> 
> ```

- 

```
    proxy_pass http://$geo.server;

```

- 

```
    proxy_pass http://$geo.server$request_uri;

```

---

<div class="post-metadata">

**Author:** ![Glen\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@Glen\_L](https://www.ruby-forum.com/u/Glen_L)\
**Post date:** [November 12, 2008, 10:12am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014/8 "2008-11-12T10:12:39Z")

</div>

Thank’s Igor it’s works successfull.

Onother question is, are we using the Load Balancer bandwidth also to  
send  
the data to the client?  
Because what we do is, I’m mirroring the server in my country, and I  
have  
onother server which is located in US

Also, I already install mod\_rpaf on the apache, and set  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_pass http://$geo.server$request\_uri;

But what I received on the apache logs, is still the load balancer IP,  
not  
the public IP

Regards,

Glen L.

---

<div class="post-metadata">

**Author:** ![Glen\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@Glen\_L](https://www.ruby-forum.com/u/Glen_L)\
**Post date:** [November 12, 2008, 10:44am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014/9 "2008-11-12T10:44:57Z")

</div>

On Wed, Nov 12, 2008 at 04:03:57PM +0700, Glen L. wrote:

> ```
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> proxy_pass http://$geo.server$request_uri;
> 
> ```
> 
> But what I received on the apache logs, is still the load balancer IP, not  
> the public IP

You should add mod\_rpaf ( [http://stderr.net/apache/rpaf/](http://stderr.net/apache/rpaf/) ) to Apache.

---

<div class="post-metadata">

**Author:** ![Glen\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@Glen\_L](https://www.ruby-forum.com/u/Glen_L)\
**Post date:** [November 12, 2008, 12:53pm UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014/10 "2008-11-12T12:53:33Z")

</div>

Will onother protocol be supported? Such as streaming and mysql load  
balancing

Regards,

## Glen L.

Sent from my BlackBerryÂ®

---

<div class="post-metadata">

**Author:** ![Glen\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@Glen\_L](https://www.ruby-forum.com/u/Glen_L)\
**Post date:** [November 13, 2008, 3:57am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014/11 "2008-11-13T03:57:34Z")

</div>

On Wed, Nov 12, 2008 at 09:40:29AM +0000, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I already install and load mod\_rpaf like already described from my previous email

Sorry, I’ve missed this line.

Can describe what address you see in this form:

1.1.1.1 (LB) \> 2.2.2.2 (nginx) \> 3.3.3.3 (apache)

?

What do you use as Load Balancer ?

---

<div class="post-metadata">

**Author:** ![Glen\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@Glen\_L](https://www.ruby-forum.com/u/Glen_L)\
**Post date:** [November 12, 2008, 10:46am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014/12 "2008-11-12T10:46:43Z")

</div>

I already install and load mod\_rpaf like already described from my  
previous email

Regards,

## Glen L.

Sent from my BlackBerryÂ®

---

<div class="post-metadata">

**Author:** ![Glen\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@Glen\_L](https://www.ruby-forum.com/u/Glen_L)\
**Post date:** [November 13, 2008, 4:01am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014/13 "2008-11-13T04:01:05Z")

</div>

Right now I just use  
1.1.1.1 (nginx) \> 2.2.2.2 (apache)  
\> 3.3.3.3 (apache) --\> located on different country

Nginx load balanced with 2 apache servers.

Also what about the bandwidth that’s used for accessing 3.3.3.3? It’s  
using  
1.1.1.1 bandwidth to access 3.3.3.3?

Regards,

Glen L.

---

<div class="post-metadata">

**Author:** ![Glen\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@Glen\_L](https://www.ruby-forum.com/u/Glen_L)\
**Post date:** [November 13, 2008, 4:09am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/153014/14 "2008-11-13T04:09:50Z")

</div>

Sorry please ignore my previous email. I forgot to enable the rpaf with  
RPAFenable On  
RPAFproxy\_ips 127.0.0.1 REALIP1 REALIP2  
RPAFsethostname On

How about the bandwidth issue?

Regards,

Glen L.
