1、反向代理配置

1.1配置upstream

upstream [proxyName] { server 192.168.1.173:8080; server 192.168.1.174:8080; server 192.168.1.175:8080; }

1.2配置server

server { listem 80; server_name www.tomcats.com;

  1. location / {
  2. proxy_pass http://tomcats;
  3. }

}

2、负载均衡配置

2.1使用加权轮询

upstream [proxyName] { server 192.168.1.173:8080 weight=1; server 192.168.1.174:8080 weight=5; server 192.168.1.175:8080 weight=2; }

2.2hash负载均衡

upstream [proxyName] { ip_hash

  1. server 192.168.1.173:8080;
  2. server 192.168.1.174:8080;
  3. server 192.168.1.175:8080;

}

hash算法实际上只会计算 192.168.1这段做哈希
使用ip_hash的注意点:

  • 不能把后台服务器直接移除,只能标记down.

    2.3url hash负载均衡

upstream [proxyName] { hash $request_url;

  1. server 192.168.1.173:8080;
  2. server 192.168.1.174:8080;
  3. server 192.168.1.175:8080;

}

2.4最小连接负载均衡

upstream [proxyName] { least_conn;

  1. server 192.168.1.173:8080;
  2. server 192.168.1.174:8080;
  3. server 192.168.1.175:8080;

}