Three parameter Settings for nginx load balancing

  • 2020-05-13 04:35:08
  • OfStack

1.


user nobody;
worker_processes 4;//1 As is CPU The number of core 
events{
  worker_connections 1024;
}

http{
  upstream mypro {
    server 182.13.32.12;
    server 213.11.23.24;
  }

  server {
    listen 8080;
    location / {
      proxy_pass http://mypro;
    }
  }
}

2. Add ip_hash to make the same user land on the same machine


use nobody;
worker_processes 4;//1 As is CPU The number of core 
events{
  worker_connections 1024;
}

http{
  upstream mypro {
    ip_hash;
    server 182.13.32.12;
    server 213.11.23.24;
  }

  server {
    listen 8080;
    location / {
      proxy_pass http://mypro;
    }
  }
}

3. Add weights


use nobody;
worker_processes 4;//1 As is CPU The number of core 
events{
  worker_connections 1024;
}

http{
  upstream mypro {
    server 182.13.32.12 weight=2;// The probability of being accessed 
    server 213.11.23.24;
  }

  server {
    listen 8080;
    location / {
      proxy_pass http://mypro;
    }
  }
}

The load balancing process can be started separately
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/fzjh.conf


Related articles: