##在linux 分别配置tomcat7和tomcat8作为区分,端口分配时8081和8082并启动
##在之前的反向代理基础上在添加一个location,直接修改nginx的挂载目录
vim /home/data/nginx/conf.d/default.conf
##请求入口
location / {
proxy_pass http://172.17.0.3/; ##该ip地址可以替换成域名
index index.html index.htm;
}
#反向代理1
location /t1/ {
proxy_pass http://192.168.159.128:8082/;
index index.html index.htm;
}
#反向代理2
location /t2/ {
proxy_pass http://192.168.159.128:8081/;
index index.html index.htm;
}
##修改ngxin挂载目录中的ngxin.conf配置项,添加upstream模块,因为是用ip访问,所以跟着ip,用域名访问就跟着域名,几个服务就配置几个server,配置好权重,机器性能好的权重大一些,反之就小一些
vim /home/data/nginx/nginx.conf
upstream 172.17.0.3 {
server 192.168.159.128:8081 weight=5;
server 192.168.159.128:8082 weight=10;
}
##重新nginx容器,直接访问ip或者域名,连续刷新会看到tomcat7和tomcat8相互切换。权重大的访问次数较多。