1.准备工作
两个或多个tomcat服务器,我这里测试的是两个
两个tomcat同时启动
在nginx.conf中进行配置:负载均衡实现有三种配置如下
(ip_hash)
upstream my_server{
ip_hash;
server ncthz.top:8080;
server ncthz.top:8081;
}
server {
listen80;
server_namelocalhost;
location / {
proxy_pass http://my_server/;
}
}
2.权重
upstream my_server{
server ncthz.top:8080 weight=10;
server ncthz.top:8081 weight=2;
}
server {
listen80;
server_namelocalhost;
location / {
proxy_pass http://my_server/;
}
}
3.轮询(踩坑:360浏览器才管用)
upstream 名字{ # 名字中不要使⽤下划线
server ip:端⼝;
server ip:端⼝;
}
server {
listen80;
server_namelocalhost;
location / {
proxy_pass http://upstream的名字/;
}
}