NginX-- configure load balancing

 

A, plus upstream module arranged at http

upstream www.myweb.com {

            server  127.0.0.1:9100 weight=3;

           server  127.0.0.1:9200 weight=1; 

}

Wherein weight = 1 represents the weight, performance for unevenness in back-end server, the access rate is approximately equal to the sum of weights ratio, the more the greater the opportunity to visit the weight

upstream is arranged nginx rear end server load balancing module is a very important , and it is also the health status of the server to check the rear end, back-end servers if one fails, the request is not forwarded to the distal end failing machine

 

B, is added in the location server in the module, and arranged proxy_pass

location /myweb {

         proxy_pass http://www.myweb.com;

}

Wherein www.myweb.com string to upstream and behind the strings are equal

 

nginx load balancing strategy:

1.1 Nginx popular load balancing strategy

1.1.1 Polling (default)

         NOTE: this is not the polling request turn each assigned to a different back-end server, and ip_hash similar, but in accordance with the access url the hash of the result of the allocation request, such that each url directed to the same back-end server, is mainly used in when the back-end server scenario for the cache . If the back-end server down off automatically removed

         upstream backserver {

             server 127.0.0.1:8080;

             server 127.0.0.1:9090;

}

1.1.2 Weight

         Each request by a certain percentage distribution to different backend servers, weight larger the percentage value greater access for the case where the uneven performance backend server

         upstream backserver {

             server 192.168.0.14 weight=5;

             server 192.168.0.15 weight=2;

}

1.1.3        ip_hash

         ip_hash also called IP bindings, each access request by ip hash of the value assigned, so that each client can access fixed access a back-end server, you can solve the session Session loss problem

         Algorithm: hash ( "124.207.55.82")% 2 = 0, 1

         upstream backserver {

             ip_hash;

             server 127.0.0.1:8080;

             server 127.0.0.1:9090;

}

1.1.4 Minimum connection

web on the request will be forwarded to the server with the fewest number of connections

         upstream backserver {

             least_conn;

             server 127.0.0.1:8080;

             server 127.0.0.1:9090;

}        

 

Guess you like

Origin www.cnblogs.com/Tpf386/p/11229116.html