nginx和tomcat负载均衡

一、       工具


  nginx-1.12.2

  apache-tomcat-8.5.29

二、       步骤

nginx和tomcat负载均衡

1、首先下载Nginx和tomcat,要下载稳定版:

nginx和tomcat负载均衡

nginx和tomcat负载均衡

nginx和tomcat负载均衡

2:然后修改这两个Tomcat的启动端口,分别为18080和28080,下面以修改第一台Tomcat为例,打开Tomcat的conf目录下的server.xml:

nginx和tomcat负载均衡

nginx和tomcat负载均衡

3、修改两个Tomcat的启动页面,分别标识两个tomcat,然后启动两个Tomcat,并访问,看是否正常:

nginx和tomcat负载均衡

nginx和tomcat负载均衡

nginx和tomcat负载均衡

4.配置Nginx来实现负载均衡,配置nginx-1.12.2\conf\nginx.conf

nginx和tomcat负载均衡

配置如下:

新增:

   #服务器的集群  
    upstream  netitcast.com {  #服务器集群名字   
        server    localhost:18080  weight=1;#服务器配置   weight是权重的意思,权重越大,分配的概率越大。  
        server    localhost:28080  weight=2;  
    }  

nginx和tomcat负载均衡

配置完成

5.我们启动Nginx:

nginx和tomcat负载均衡

6.localhost:80访问会显示不同的页面。