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 为等待应用服务器响应的超时时间,单位为秒