tomcat+nginx 横向扩展

1.分别在电脑上部署两个tomcat

tomcat1  tomcat2

2.不是nginx 并启动

输入 localhost 并进入nginx欢迎界面,证明部署成功

3.修改nginx 配置

nginx.conf

在server定义服务集群

upstream test{

server localhost:8080;

server localhost:8081;

#是session共享,但必须nginx是最前台的,切分配的最后台也是他
ip_hash;

}

server {
listen 80;
server_name localhost;

location / {

proxy_pass http://test;

proxy_redirect off;
#转发请求路径头,不然后台取得的数据是nginx的头
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

#root html;
#index index.html index.htm;
}

 

}

 

4.将nginx 重启
nginx -s reload

5.输入登入nginx首页的路径,就会在两个TOMCAT中来回切换

posted on 2016-08-31 16:49  sui008  阅读(548)  评论(0编辑  收藏  举报

导航