Several configurations for nginx upstream

  

nginx upstream currently supports 4 ways of allocation 1, polling (default)


Each request is assigned one by one in chronological order Different backend servers can be automatically culled if the backend server is down.


2, weight

Specify the polling probability, which is proportional to the access ratio and is used for the performance of the backend server.

Example:

upstream bakend {

server 192.168.0.14 weight=10;

server 192.168.0.15 weight=10;

}


2, ip_hash

Each request is assigned by the hash result of the access ip, so that each visitor can access a backend server to solve the session problem. .

Example:

upstream bakend {

ip_hash;

server 192.168.0.14:88;

server 192.168.0.15:80 ;

}


3, fair (third party)

Assigning requests by response time of the backend server, short response priority allocation .

upstream backend {

server server1;

server server2;

fair;

}


4, url_hash (third party)


Assign the request by the hash result of the access url, so that each url is directed to the same backend server, the backend server is cached It is more effective.


Example: Adding a hash statement in the upstream, the server statement can not write weight and other parameters, hash_method is the hash algorithm used


upstream backend {

server squid1:3128;

server squid2:3128;

hash $request_uri;

hash_method crc32;

}


tips:


upstream bakend{#Define Ip and device status of load balancing devices

ip_hash;< Br>

server 127.0.0.1:9090 down;

server 127.0.0.1:8080 weight=2;

server 127.0.0.1:6060;

server 127.0 .0.1:7070 backup;

}

Adding

proxy_pass http://bakend/;


to servers that need to use load balancing >

The status of each device is set to:

1.down means that the server before the single is not involved in the load temporarily

2.weight The default is 1.weight is bigger, the weight of the load It is bigger.

3.max_fails : The number of times a request is allowed to fail defaults to 1. When the maximum number of times is exceeded, the error defined by the proxy_next_upstream module is returned

4.fail_timeout: The time after the failure of max_fails times.

5.backup: When all other non-backup machines are down or busy, request a backup machine. So this machine will be the lightest.


nginx supports multiple sets of load balancing at the same time, which is used for unused servers.


client_body_in_file_only Set to On. You can talk about the data from the client post to the file for debugging.

client_body_temp_path Set the directory of the log file to up to 3 levels. Br>


location Match URLs. You can redirect or perform new proxy load balancing

Copyright © Windows knowledge All Rights Reserved