1.nginx做tomcat集群
测试环境:
nginx:1.16
tomcat:8.5
jdk:1.8
项目类型:maven单体应用项目
1.1nginx集群配置
nginx.cfg文件修改:
http {
//以下为添加的内容
upstream nginxTest {
#ip_hash;
server 192.168.43.23:9080 weight=1;//tomcat应用服务器的地址与权重
server 192.168.43.23:9081 weight=1;//tomcat应用服务器的地址与权重
server 192.168.43.23:9082 weight=1;//tomcat应用服务器的地址与权重
}
//添加结束
//nginx做请求转发
server {
listen 80;
server_name www.tomcatTest.com;//在C:\Windows\System32\drivers\etc\hosts做域名映射
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://nginxTest;//这里写上方的server名称
root activiti-app/;这里写tomcat下项目名称
index index.html index.htm;这里写跳转的首页路径
}
2.tomcat所做的配置
复制tomcat两份以上,在server中做端口的配置,需要修改三个地方
3.tomcat开启集群配置,解决session不共享问题
a.在tomcat中的server.xml开启cluster的标签即可
b.在项目的web.xml中加入<distributable/>标签
大功告成了!!!