nginx实现负载均衡

nginx实现负载均衡只需要修改一下配置文件:

 upstream localhost {
    server 112.74.46.45:8080 weight=1 max_fails=2    fail_timeout=30s;
    server localhost:8080 weight=3 max_fails=2 fail_timeout=30s;
}

    server {
        listen       10000;
        server_name  test;
        location / {
            proxy_pass http://localhost;
            proxy_redirect default;
        }
      }

配置文件解析:当访问localhost:10000时会反向代理到112.74.46.45:8080服务器或者localhost:8080服务器上,便实现了负载均衡。可以更改一个tomcat的主页目录,看其是不是轮询到不同的服务器上。

原文地址:https://www.cnblogs.com/wangxiaopei/p/8551198.html