Nginx summary (six) nginx load balancing

Speaking in front of how to configure Nginx virtual host, you can go here to see nginx series: https://www.cnblogs.com/zhangweizhong/category/1529997.html

I say today is how to configure nginx and tomcat achieve reverse proxy.

Note: Because this article is nginx in a series of articles, article there are many other configurations, may have said previous article talked about, then there would be no follow-up in the introduction, did not say if some configuration occurs, you may need to to see the previous article.

 

What is load balancing

         Load balancing is based on an existing network architecture, it provides a cheap and effective way to extend the bandwidth of transparent network devices and servers increase throughput, enhance network data processing capability, flexibility, and availability of the network.

         Load balancing, the English name for the Load Balance, which means that spread over multiple operating units to perform, such as Web servers, FTP servers, business-critical application servers and other mission-critical servers, so as to work together to complete the task.

 

Nginx load balancing

i. Demand

         As nginx server load balancing, the user first reaches nginx request, then forwards the request nginx load configuration according to the tomcat server.

         nginx load balancing servers: 192.168.78.132

         tomcat1 server: 192.168.78.134

         tomcat2 server: 192.168.78.135

 

ii. Environmental preparation

  1. Two tomcat server, I used here is to use apache-tomcat-7.0.57 version, start tomcat on 192.168.78.134 and 192.168.78.135 virtual machine.

  2. Nginx server, the previously installed, ip address is: 192.168.78.132

  3. Modify the contents of the webapps two tomcat / ROOT / index.jsp, the use of two services tomcat1 and tomcat2 Home display different content.

  4. Specify aaa.test.com by host name resolution files, correspondence 192.168.78.132 virtual machine: Modify window hosts file: (C: \ Windows \ System32 \ drivers \ etc)

192.168.78.132 aaa.test.com

 

iii. Configuration Nginx

Add the following configuration according to the needs of the top node in nginx.conf http file:

   upstream tomcat_server_pool{

        server 192.168.101.5:8080 weight=10;

        server 192.168.101.6:8080 weight=10;

    }


    server {

        listen 80;

        server_name aaa.test.com;

        location / {

                 proxy_pass http://tomcat_server_pool;

                 index index.jsp index.html index.htm;

        }

    }

Related parameters:

down: Indicates the former single-server is temporarily not participate in load

weight: 1.weight default is greater, the greater the weight load of weight.

max_fails: the number of permitted requests failed 1. When the default maximum number of attempts, the module defined error return proxy_next_upstream

fail_timeout: After max_fails failed, pause time.

backup: all other non-backup machine down or busy, requests backup machine. So this machine will be the lightest pressure.


iv. Test
 

Request aaa.test.com, we will find, nginx forwards the request to each tomcat server.

 

At last

Nginx above will be introduced over load balancing. Nginx's high availability will introduce later.

 

Guess you like

Origin www.cnblogs.com/zhangweizhong/p/11378566.html