NGINX + Load Balancing + GeoIP

tainted nginx-forum at
Fri Feb 25 21:26:54 MSK 2011

Hi everyone,

Has anyone got ngix + load balancing + geoip working nicely?

I have a nginx server load balancing two webservers and would like to
add in GeoIP to the mix.

Config :

My config file.

worker_processes  1;

events {
    worker_connections  1024;

http {
    ### SET the path to the .dat file used for determining the visitor's
country from the IP-address ###
    geoip_country /var/lib/GeoIP/GeoIP.dat;

    ### SET FASTCGI Variables ###
    fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
    fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;
    fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    upstream webcluster {
    server websvr01:80;
    server websvr02:80;


server {
location / {
       proxy_pass  http://webcluster;
       proxy_set_header Host $host;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;




I would like to set it up that those in the UK goto certain webservers,
those in USA goto another set of servers and so on.

Appreciate any help or feedback.

Take care and have a great weekend.

Posted at Nginx Forum:,178453,178453#msg-178453

More information about the nginx mailing list