Nginx配置多个Tomcat实现负载均衡

1.下载Nginx:http://nginx.org/en/download.html    

例如:1.12.2

nginx/Windows-1.12.2

2.启动Nginx两种方式

(1)解压文件,运行nginx.exe

(2)cmd打开nginx解压文件路径,执行start nginx命令(重载:nginx -s reload,退出:nginx -s quit)

3.浏览器访问:http://localhost,显示Welcome to nginx欢迎页面,则启动成功

4.修改nginx.conf配置文件分发到多个Tomcat

(1)server标签外添加:

upstream tomcats {  
    ip_hash;
    server localhost:82 weight=2;
    server localhost:8080 weight=1;		
}

备注:localhost:82 和 localhost:8080 为已启动的两个应用,weight设置越高,代表权重越大,例如:有3个请求,有2个会发送到 localhost:82 应用上,有1个会发送到 localhost:8080 应用上。配置ip_hash可解决session共享问题,只会请求localhost:82上的session

(2)server标签内修改:

location / {
    proxy_pass http://tomcats;
    proxy_connect_timeout 36000s;
    proxy_send_timeout 36000s;
    proxy_read_timeout 36000s;
}

  备注:proxy_connect_timeout 为连接应用服务器的超时时间,单位为秒

             proxy_send_timeout 为发送请求到应用服务器的超时时间,单位为秒

             proxy_read_timeout 为等待应用服务器响应的超时时间,单位为秒

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值