Nginx Load Balancing implementation

Source: Internet
Author: User
Tags nginx reverse proxy nginx load balancing

Nginx Load Balancing implementation

I. Load Balancing Methods
1. Round Robin

Upstream test_up {
Server localhost: 8080;
Server localhost: 9090;
Server localhost: 9090;
}

Server {
Listen 80;
Server_name test;

Location/test.html {
Proxy_pass http: // test_up;
}}

When you enter http: // test/test.html in the address bar of the browser, nginx accesses the backend server in sequence as configured in test_up.

2. Weight Distribution

Upstream test_up {
Server localhost: 8080 weight = 1;
Server localhost: 9090 weight = 2;
}

Server {
Listen 80;
Server_name test;

Location/test.html {
Proxy_pass http: // test_up;
}
}

Based on the distribution of weights, NGINX dynamically allocates frontend requests to backend servers.

3. ip hash allocation

Upstream test_up {
Server localhost: 8080 weight = 1;
Server localhost: 9090 weight = 2;
Ip_hash;
}

Server {
Listen 80;
Server_name test;

Location/test.html {
Proxy_pass http: // test_up
}
}

The ip hash method is to HASH client requests to backend Servers Based on the Client IP address.

Note: although the weight is configured after each server in the code above, the weight does not take effect after ip hash is adopted.

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

Nginx supports setting multiple groups of server Load balancer instances for unused servers.
Client_body_in_file_only is set to On. You can use the client post data record in the file for debugging.
Client_body_temp_path: Set the directory of the record file to a maximum of three levels.
Location matches the URL. You can perform redirection or perform new proxy load balancing.

-------------------------------------- Split line --------------------------------------

Thoughts on how to configure and set up Nginx reverse proxy

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.