trssc 发表于 2018-11-14 13:01:47

nginx如何搭建负载均衡?

  upstream resinserver{            # 定义负载均衡设备的Ip及设备状态
  ip_hash;
  server 10.1.1.1:8000 down;
  server 10.1.1.2:8080 weight=10 max_fails=3 fail_timeout=10s;
  server 10.1.1.3:6801 weight=20 max_fails=3 fail_timeout=10s;
  server 10.1.1.4:6802 backup;
  }
  server {
  listen 80;
  location / {
  proxy_pass http://www.hzcto.com;   # 指向上面设置反向代理转发的服务器
  proxy_set_header   Host             $host;
  proxy_set_header   X-Real-IP      $remote_addr;
  proxy_set_header   X-Forwarded-For$proxy_add_x_forwarded_for;
  }
  }
  设备的状态:
  1.down      表示当前的server暂时不参与负载
  2.weight   权重,默认为1。权值越高被分配到的几率越大
  3.maxfails   许请求失败的次数默认为1.当超过最大次数时,返回proxynextupstream 模块定义的错误
  4.failtimeout maxfails 多少次失败后,暂停的时间。
  5.backup   其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。
  nginx支持同时设置多组的负载均衡,用来给不用的server来使用。
  clientbodyinfileonly 设置为On 可以讲client post过来的数据记录到文件中用来做debug
  clientbodytemppath 设置记录文件的目录 可以设置最多3层目录
  location 对URL进行匹配.可以进行重定向或者进行新的代理 负载均衡**

页: [1]
查看完整版本: nginx如何搭建负载均衡?