# Nginx load balancer with geoip?

**URL:** <https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/217478>\
**Category:** NGINX\
**Created:** [March 2, 2012, 3:31pm UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/217478 "2012-03-02T15:31:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 2, 2012, 3:31pm UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/217478/1 "2012-03-02T15:31:49Z")

</div>

i wrote all geoip database in geo.conf, and i wrote these lines in http  
segment.  
geo $geo {  
include geo.conf;  
}

and I set upstream in http segment like:  
upstream default {  
server [folderfile.net](http://folderfile.net);  
}

upstream kr {  
server [nixneo.com](http://nixneo.com);  
}

and added server segment and set proxy\_pass.  
server {  
listen 80;  
server\_name [geotest.folderfile.net](http://geotest.folderfile.net);

location / {  
proxy\_pass http://$geo;  
}

work looks fine, request in korea perfectly proxied to [nixneo.com](http://nixneo.com) and  
other requests go to [folderfile.net](http://folderfile.net) BUT! the problem appeared.  
you can see the problem in this url :  
[http://geotest.folderfile.net/index.php?mid=talkboard](http://geotest.folderfile.net/index.php?mid=talkboard) (original  
url:[http://delphixe.folderfile.net/index.php?mid=talkboard](http://delphixe.folderfile.net/index.php?mid=talkboard))  
can’t see the problem? let you explain it.  
see my image : [http://img717.imageshack.us/img717/3426/gipp.png](http://img717.imageshack.us/img717/3426/gipp.png)

how can I solve this problem? please help!

Posted at Nginx Forum:

> **[nginx load balancer with geoip?](https://forum.nginx.org/read.php?2,223278,223278#msg-223278)**
>
> i wrote all geoip database in geo.conf, and i wrote these lines in http segment. geo $geo { include geo.conf; } and I set upstream in http segment like: upstream default { server folderfile.net; } upstream kr { server nix

---

<div class="post-metadata">

**Author:** ![delphixe2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@delphixe2](https://www.ruby-forum.com/u/delphixe2)\
**Post date:** [March 2, 2012, 8:50pm UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/217478/2 "2012-03-02T20:50:23Z")

</div>

On Fri, Mar 02, 2012 at 09:31:05AM -0500, delphixe2 wrote:

Hi there,

> work looks fine, request in korea perfectly proxied to [nixneo.com](http://nixneo.com) and  
> other requests go to [folderfile.net](http://folderfile.net) BUT! the problem appeared.  
> you can see the problem in this url :

I can’t get to [folderfile.net](http://folderfile.net), so I can’t test this directly.

> [http://geotest.folderfile.net/index.php?mid=talkboard](http://geotest.folderfile.net/index.php?mid=talkboard) (original  
> url:[http://delphixe.folderfile.net/index.php?mid=talkboard](http://delphixe.folderfile.net/index.php?mid=talkboard))  
> can’t see the problem? let you explain it.  
> see my image : [ImageShack: Image Hosting & Photo Sharing](http://img717.imageshack.us/img717/3426/gipp.png)

I _think_ this says “the proxied server creates links to its local  
resources using http:// and whatever the client sent in the Host:  
header”.

You can try adding

proxy\_set\_header Host $host;

> location / {  
> proxy\_pass http://$geo;  
> }

inside that location, so that the Host: header used will probably be  
resolvable by the client.

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![delphixe2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@delphixe2](https://www.ruby-forum.com/u/delphixe2)\
**Post date:** [March 3, 2012, 4:46am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/217478/3 "2012-03-03T04:46:54Z")

</div>

I tried that, and I get 500 Internal Server Error.  
and more lines what I tested :  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;

in any case, dosen’t worked.

temporarily, I solved problem.  
upstream [default.folderfile.net](http://default.folderfile.net) {  
server [folderfile.net](http://folderfile.net);  
}  
upstream [kr.folderfile.net](http://kr.folderfile.net) {  
server [nixneo.com](http://nixneo.com);  
}

location / {  
proxy\_pass http://$geo.folderfile.net;  
}

and I added record for [default.folderfile.net](http://default.folderfile.net) → [folderfile.net](http://folderfile.net)’s server  
IP & [kr.folderfile.net](http://kr.folderfile.net) → [nixneo.com](http://nixneo.com)’s IP  
so, that image appeared, the link was :  
[http://default.folderfile.net/modules/document/tpl/icons/file.gif](http://default.folderfile.net/modules/document/tpl/icons/file.gif)

but… It is incomplete solution.

- now, you can see that site. I opened my server.

Posted at Nginx Forum:

> **[Re: nginx load balancer with geoip?](https://forum.nginx.org/read.php?2,223278,223291#msg-223291)**
>
> i wrote all geoip database in geo.conf, and i wrote these lines in http segment. geo $geo { include geo.conf; } and I set upstream in http segment like: upstream default { server folderfile.net; } upstream kr { server nix

---

<div class="post-metadata">

**Author:** ![delphixe2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@delphixe2](https://www.ruby-forum.com/u/delphixe2)\
**Post date:** [March 4, 2012, 10:23am UTC](https://www.ruby-forum.com/t/nginx-load-balancer-with-geoip/217478/4 "2012-03-04T10:23:53Z")

</div>

On Fri, Mar 02, 2012 at 10:46:20PM -0500, delphixe2 wrote:

Hi there,

you’ve found something that works for you, so you can stay with that  
configuration.

However:

> I tried that, and I get 500 Internal Server Error.

I find that it is usually worth understanding _why_ configurations fail,  
so it might be worth investigating happened there.

> and more lines what I tested :  
> proxy\_set\_header X-Real-IP $remote\_addr;  
> proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;

They can be useful if the proxied server is configured to care about  
them.

> }
> 
> and I added record for [default.folderfile.net](http://default.folderfile.net) → [folderfile.net](http://folderfile.net)’s server  
> IP & [kr.folderfile.net](http://kr.folderfile.net) → [nixneo.com](http://nixneo.com)’s IP

Perhaps [nixneo.com](http://nixneo.com) responds differently based on the source address; but  
from where I am, it looks like you have a redirector, not a reverse  
proxy.

When I access the IP address of [nixneo.com](http://nixneo.com), if I make a http request  
with anything other than a Host: header of “[nixneo.com](http://nixneo.com)”, I get a 302  
redirect to [http://nixneo.com/](http://nixneo.com/)

So to get useful content back in a proxy\_pass location, I’d need to set  
the correct Host header.

All the best,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
