Nginx基础08:Nginx负载均衡

http {

  #webapp  代理服务器,名称myapp自定义
  upstream myapp {

     #server 访问服务器IP:端口;weight 权重,两个都设置1表示访问量平分;max_fails 失败次数,如果失败次数>值,则表示该节点已宕机;fail_timeout 连接超时时间
     server 192.168.1.171:8080 weight=1 max_fails=2 fail_timeout=30s;
     server 192.168.1.172:8080 weight=1 max_fails=2 fail_timeout=30s;
  }  

  #返回的相应文件地址
  location / {
  #设置客户端真实ip地址
  proxy_set_header X-real-ip $remote_addr;
  #负载均衡反向代理
  proxy_pass http://myapp;

  #返回根路径地址(相对路径:相对于/usr/local/nginx/)
  root html;
  #默认访问文件
  index index.html index.htm;
  }

}

原文地址:https://www.cnblogs.com/chai-blogs/p/13063000.html