nginx + tomcat 集群

下载安装nginx

brew install nginx

其被安装路径 /usr/local/etc/nginx
启动命令

sudo nginx

接着输入个人密码就可以了
浏览器访问
localhost:8080
nginx + tomcat 集群_第1张图片
关闭命令

sudo nginx -s stop

复制多份tomcat,命名为 tomcat-1、tomcat-2
修改他们的server.xml文件,即 tomcat-1以81开头、tomcat-2以82开头

//tomcat-1的server.xml
"8105" shutdown="SHUTDOWN">
"UTF-8" connectionTimeout="20000" port="8180" protocol="HTTP/1.1" redirectPort="8443"/>
"8109" protocol="AJP/1.3" redirectPort="8443"/>
//tomcat-2的server.xml
"8205" shutdown="SHUTDOWN">
"UTF-8" connectionTimeout="20000" port="8280" protocol="HTTP/1.1" redirectPort="8443"/>
"8209" protocol="AJP/1.3" redirectPort="8443"/>

然后到各个tomcat的bin目录下启动服务器

cd $TOMCAT_HOME/bin
./startup.sh

可以通过浏览器查看效果
localhost:8180 和 localhost:8280

接下来配置nginx,找到ngnix.conf文件并修改

//添加
 upstream localhost {
      #ip_hash; 
      server localhost:8180;
      server localhost:8280;
    }

//修改
 location / {
            root html;
            index index.html index.htm;
            proxy_pass  http://localhost;  
            proxy_set_header X-Real-IP $remote_addr; 
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
            proxy_redirect HOST default; 
        }

启动nginx即
sudo nginx

然后各种测试请求是否随机到各台tomcat服务器

你可能感兴趣的:(无头无尾)