Bootstrap

部署2台服务器负载均衡

1、安装nginx

2、2台服务器分别准备好tomcat项目

3、配置项目端口 

服务器129:修改端口

vim /tomcat/conf/service.xml

Server port="8005" 

Connector port="9091" 

服务器128:修改端口

vim /tomcat/conf/service.xml

Server port="8015"

Connector port="9091"

4.分别启动2台服务器的tomcat

5.配置nginx/conf/nginx.conf

    #gzip  on;

    upstream dataex {
        ip_hash;
        server xxx.xxx.xxx.128:9091 weight=5;
        server xxx.xxx.xxx.129:9091 weight=5;
    }

    server {
        listen       8080;
        server_name  localhost;   #xxx.xxx.xxx.129

        client_max_body_size 200M;

        gzip on;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        gzip_comp_level 5;
        gzip_types text/plain application/x-javascript application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        gzip_vary on;


        location /dataex {
            proxy_pass http://dataex/dataex;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Origin '';
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_read_timeout 1800;
            proxy_connect_timeout 1800;
            root   html;
            index  index.html index.htm;
         }

......

}

6、启动nginx

cd /home/dacp/nginx
sbin/nginx  -c conf/nginx.conf  

7、以后更新配置时重启使新配置生效

sbin/nginx -s  reload #重启

 

;