Nginx load balancer with geoip?

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 nixneo.com;
}

and added server segment and set proxy_pass.
server {
listen 80;
server_name geotest.folderfile.net;

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

work looks fine, request in korea perfectly proxied to nixneo.com and
other requests go to folderfile.net BUT! the problem appeared.
you can see the problem in this url :
http://geotest.folderfile.net/index.php?mid=talkboard (original
url: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

how can I solve this problem? please help!

Posted at Nginx Forum:

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 and
other requests go to folderfile.net BUT! the problem appeared.
you can see the problem in this url :

I can’t get to folderfile.net, so I can’t test this directly.

http://geotest.folderfile.net/index.php?mid=talkboard (original
url: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

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. [email protected]

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 {
server folderfile.net;
}
upstream kr.folderfile.net {
server nixneo.com;
}

location / {
proxy_pass http://$geo.folderfile.net;
}

and I added record for default.folderfile.netfolderfile.net’s server
IP & kr.folderfile.netnixneo.com’s IP
so, that image appeared, the link was :
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:

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.netfolderfile.net’s server
IP & kr.folderfile.netnixneo.com’s IP

Perhaps 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, if I make a http request
with anything other than a Host: header of “nixneo.com”, I get a 302
redirect to 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. [email protected]