nginx安装与配置4-负载均衡

负载均衡:
1、准备俩tomcat,测试环境端口不一样,然后服务名一样然后内容不一样
2.配置nginx的config
在http模块中设置:
//举例,以下IP,端口无效
 upstream test{ 
      server 11.22.333.11:6666 weight=1; 
      server 11.22.333.22:8888 down; 
      server 11.22.333.33:8888 backup;
      server 11.22.333.44:5555 weight=2; 
}
//down 表示单前的server临时不參与负载.
//weight 默觉得1.weight越大,负载的权重就越大
//backup: 其他全部的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻

访问:http://localhost:9999/etc/a.html
conf文件中:
worker_processes  1;

events {
    worker_connections  1024;
}


http {
   upstream  dalaoyang-server {
       server    localhost:8080 weight=1;
       server    localhost:8081 weight=11;
   }

   server {
       listen       9999;
       server_name  localhost;

       location / {
        proxy_pass http://dalaoyang-server;
        proxy_redirect default;
      }

    }

}

  

posted @ 2020-12-14 01:11  三号小玩家  阅读(71)  评论(0编辑  收藏  举报
Title
三号小玩家的 Mail: 17612457115@163.com, 联系QQ: 1359720840 微信: QQ1359720840