Home > Operation and Maintenance > Nginx > What are the nginx load balancing parameters?

What are the nginx load balancing parameters?

(*-*)浩
Release: 2019-06-18 11:07:14
Original
4708 people have browsed it

Nginx can be configured to proxy multiple servers. When a server goes down. The system remains available. Let’s talk about some commonly used configuration items.

What are the nginx load balancing parameters?

upstream configuration:

Just add upstream configuration under http configuration:

upstream nodes {
    server 192.168.10.1:8668;
    server 192.168.10.2:8668;
}
Copy after login

upstream makes requests to the configured upstream server according to the default polling method. If the upstream server hangs up, it can be automatically removed without manual intervention. This method is simple and quick. But if the upstream server configuration is imbalanced, it cannot be solved. So nginx has many other configuration items. Let’s introduce them one by one.

Weight configuration:

Weight is proportional to the number of requests and is mainly used when the upstream server configuration is unbalanced. In the configuration below, the request volume of the 192.168.10.2 machine is twice the request volume of the 192.168.10.1 machine.

upstream nodes {
    server 192.168.10.1:8668 weight=5;
    server 192.168.10.2:8668 weight=10;
}
Copy after login

ip_hash configuration:

Each request is allocated according to the hash result of the requested IP. In this way, each request is fixed on an upstream server, which can solve the problem of IP sessions on the same server.

upstream nodes {
    ip_hash;
    server 192.168.10.1:8668;
    server 192.168.10.2:8668;
}
Copy after login

fair configuration:

Distribute requests according to the response time of the upstream server. Prioritize allocation with short response times.

upstream nodes {
    server 192.168.10.1:8668;
    server 192.168.10.2:8668;
    fair;
}
Copy after login

url_hash configuration:

Distribute requests according to the hash result of the accessed URL, so that each URL is directed to the same upstream server. Note: Add hash statement in upstream. Other parameters such as weight cannot be written in the server statement. hash_method is the hash algorithm used.

upstream nodes {
    server 192.168.10.1:8668;
    server 192.168.10.2:8668;
    hash $request_uri;
    hash_method crc32;
}
Copy after login

down: Indicates that the current server does not participate in load balancing.

max_fails: The number of failed requests defaults to 1.

fail_timeout: The time to pause requests to this server after max_fails failures.

backup: When all other non-backup machines are down or busy, request the backup machine. So this machine will have the least pressure.

For more Nginx related technical articles, please visit the Nginx usage tutorial column to learn!

The above is the detailed content of What are the nginx load balancing parameters?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template