nginx 搭建简单tomcat 集群

在服务器上准备两个tomcat 端口分别改为8801、8802,准备两个war 包,index.js 分别显示 tomcat-8801,tomcat-8802  

放入对应的tomcat 中,并启动它们

nginx 安装可参照 :https://www.cnblogs.com/xxoome/p/5866475.html

安装好nginx 之后修改配置文件 nginx.conf

在下图位置中添加如下代码

upstream tomcatCluster{
  server 127.0.0.1:8801 weight=1;
  server 127.0.0.1:8802 weight=2;
}

proxy_pass http://tomcatCluster;

重新启动nginx  报错

-bash: nginx: command not found

解决办法:

1、vim /etc/profile  添加 内容

PATH=$PATH:/usr/local/nginx/sbin
export PATH

如下

2,source /etc/profile    让配置文件重新生效一下

重启 nginx 命令  在sbin目录下执行  nginx -s stop(停止nginx)  nginx(启动)

如下图nginx 启动成功

 请求服务器地址 如下 一直刷新的话 会在8801 和8802 之间切换 tomcat 集搭建成功

原文地址:https://www.cnblogs.com/feathe/p/12603345.html