Home  >  Article  >  Backend Development  >  Several configuration methods of nginx upstream

Several configuration methods of nginx upstream

WBOY
WBOYOriginal
2016-08-08 09:18:572246browse

Reprinted from: http://lihuipeng007.blog.163.com/blog/static/12108438820108206101535/1. Polling (default)Each request is assigned to a different backend one by one in chronological order Server, if the backend server goes down, it can be automatically eliminated. 2. Weight
specifies the polling probability. Weight is proportional to the access ratio and is used when the performance of the back-end server is uneven.
For example:
upstream bakend {
server 192.168.0.14 weight=10;
server 192.168.0.15 weight=10;
}3. ip_hash
Each request is allocated according to the hash result of the accessed IP, so that each visitor has a fixed access A backend server can solve session problems.
For example:
upstream bakend {
ip_hash;
server 192.168.0.14:88;
server 192.168.0.15:80;
}4. fair (third party)
Allocate requests and responses according to the response time of the backend server Priority is given to short-term assignments.
upstream backend {
server server1;
server server2;
fair;
}5. url_hash (third party) Distribute requests according to the hash result of the accessed url, so that each url is directed to the same backend server. It is more effective when the backend server is cached. Example: Add a hash statement to upstream. Other parameters such as weight cannot be written in the server statement. hash_method is the hash algorithm usedupstream backend {
server squid1:3128;
server squid2:3128;
hash $request_uri ;
hash_method crc32;
}upstream bakend{#Define the IP and device status of the load balancing device
ip_hash;
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;
}
In the server that needs to use load balancing, add
proxy_pass http://bakend/;The status of each device is set to:
1.down means single front The server does not participate in the load for the time being
2.weight The default is 1. The larger the weight, the greater the weight of the load.
3.max_fails: The number of allowed request failures defaults to 1. When the maximum number is exceeded, the error defined by the proxy_next_upstream module is returned.
4.fail_timeout: The pause time after max_fails failures.
5.backup: When all other non-backup machines are down or busy, request the backup machine. So this machine will have the least pressure. nginx supports setting up multiple groups of load balancing at the same time for use by unused servers. client_body_in_file_only Set to On, the data posted by the client can be recorded into a file for debugging
client_body_temp_path Set the directory of the recording file to set up to 3 levels of directories location matches the URL. You can redirect or create a new one Proxy load balancing

The above introduces several configuration methods of nginx upstream, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP gets user IP addressNext article:PHP gets user IP address