NGINX + Load Balancing + GeoIP

i-comers nginx-forum at
Fri Mar 11 05:01:19 MSK 2011

I'not master but just trying to help you :)
for rist you must to know All of UK IP Address range before.

This just example only:
i make file uk_ip.conf and save on /usr/local/geoip/uk_ip.conf
on file uk_ip.conf put all uk ip address uk; uk;
and next... uk ip address

One more i want also to add us country ip address
i make file us_ip.conf and save on /usr/local/geoip/us_ip.conf us; us; us;
and next... us ip address

And this file of nginx.conf you can see:
This just example only i say you must use your own skill to
configuration your own server

#Nginx Master configuration
user  nobody;
error_log  logs/error.log;
#Number of worker you need
worker_processes  1;
# How many connections a worker can handle maximum.
events {
    worker_connections 50000;
http {
	include    mime.types;
 	default_type  application/octet-stream;
 	sendfile on;
	server_names_hash_max_size 10000;
        server_names_hash_bucket_size 1024;
 	tcp_nopush on;
 	tcp_nodelay on;
 	keepalive_timeout  10;
 	gzip on;
 	gzip_min_length  1100;
 	gzip_buffers  4 32k;
 	gzip_types    text/plain  application/x-javascript text/xml text/css;
 	ignore_invalid_headers on;
 	client_header_timeout  3m;
 	client_body_timeout 3m;
 	send_timeout     3m;

geo $geo {
	default default;  // for default server
	include /usr/local/geoip/uk_ip.conf;  // if uk ip address comming found
in this database
	include /usr/local/geoip/us_ip.conf;  // if us ip address comming found
in this database

// Now you make first default server if that ip address comming no one
in your ip address database country
upstream default.webserver {
       server weight=4;

// you can see i'm put also option weight that configuration will send
80% of the request to
// and another 20% to

// now here put server for access from uk country
upstream uk.webserver {

// And nginx load balancing have more option 
// Like Option: weight, max_fails, fail_timeout, down, backup more go to
// Example i will using option max_fails and backup for ip address
comming from us

upstream us.webserver {
       server max_fails=3;
       server max_fails=3;
       server backup;

// that mean will send 50% of the requests for to and other 50% 
// to if your server1 & both
fails 3times requests 
// will be send requests to as backup server.

server {
 #access_log on; 
 listen    80;

location / {
  client_max_body_size    10m;
  client_body_buffer_size 128k;
  proxy_send_timeout   60;
  proxy_read_timeout   60;
  proxy_buffer_size    16k;
  proxy_buffers     4 32k;
  proxy_busy_buffers_size 32k;
  proxy_temp_file_write_size 64k;
  proxy_connect_timeout 30s;

        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.webserver$request_uri;

i'm use that configuration for my website but only little different
methode :)
hope this can help you to make your server loadbalace :)



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

More information about the nginx mailing list