Introduction to upstream polling mechanism in Nginx

Source: Internet
Author: User

Introduction to upstream polling mechanism in Nginx

In Nginx, upstream has the following methods:

1. Round Robin (weight = 1)
By default, when weight is not specified, the weight of each server is the same, and each request is allocated to different backend servers one by one in chronological order. If the backend server is down, it can be automatically removed.

Upstream bakend {
Server 192.168.1.10;
Server 192.168.1.11;
}
 

2. weight
Specify the round-robin probability. weight is proportional to the access ratio, which is used when the backend server performance is uneven.
If the backend server is down, it can be removed automatically.
For example, in the following configuration, the access volume of the 1.11 server is twice that of the 1.10 server.


Upstream bakend {
Server 192.168.1.10 weight = 1;
Server 192.168.1.11 weight = 2;
}
 

3. ip_hash
Each request is allocated according to the hash result of the access ip address. In this way, each visitor accesses a backend server at a fixed time, which can solve the problem that the session cannot be cross-server.
If the backend server is down, it must be down manually.

Upstream resinserver {
Ip_hash;
Server 192.168.1.10: 8080;
Server 192.168.1.11: 8080;
}
 

4. fair (third-party plug-in)
Requests are allocated based on the response time of the backend server. Requests with short response time are prioritized.

Upstream resinserver {
Server 192.168.1.10: 8080;
Server 192.168.1.11: 8080;
Fair;
}

5. url_hash (third-party plug-in)
Requests are allocated according to the hash result of the access url so that each url is directed to the same backend server, which is effective when the backend server is the cache server.
Add a hash statement to upstream. hash_method is the hash algorithm used.

Upstream resinserver {
Server 192.168.1.10: 8080;
Server 192.168.1.11: 8080;
Hash $ request_uri;
Hash_method crc32;
}

The status of the device is:
1. down indicates that the server before a ticket is not involved in the load
2. weight. The default value is 1. The larger the weight, the larger the load weight.
3. The default number of failed requests allowed by max_fails is 1. If the maximum number of times is exceeded, an error defined by the proxy_next_upstream module is returned.
4. The time when the max_fails operation fails.
5. backup Server. When all other non-backup machines are down or busy, the backup server is requested. Therefore, this machine is under the least pressure.

Deployment of Nginx + MySQL + PHP in CentOS 6.2

Build a WEB server using Nginx

Build a Web server based on Linux6.3 + Nginx1.2 + PHP5 + MySQL5.5

Performance Tuning for Nginx in CentOS 6.3

Configure Nginx to load the ngx_pagespeed module in CentOS 6.3

Install and configure Nginx + Pcre + php-fpm in CentOS 6.4

Nginx installation and configuration instructions

Nginx log filtering using ngx_log_if does not record specific logs

Nginx details: click here
Nginx: click here

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.