Nginx reverse proxy, Server Load balancer, page cache, URL rewriting, and read/write splitting

Source: Internet
Author: User
The load balancing module is used to select a host from the list of backend hosts defined by the "upstream" command. Nginx first finds a host using the Server Load balancer module, and then uses the upstream module to interact with this host. To facilitate the introduction of the Server Load balancer module, the following uses the built-in nginx iPhone ash module as an example for analysis. Server Load balancer module (100%)

The load balancing module is used to select a host from the list of backend hosts defined by the "upstream" command. Nginx first finds a host using the Server Load balancer module, and then uses the upstream module to interact with this host. To facilitate the introduction of the Server Load balancer module, the following describes how to use the built-in ip hash module of nginx as an example.

Configuration

To understand the development method of the Server Load balancer module, you must first understand how to use the Server Load balancer module. Because the load balancing module differs greatly from the modules mentioned in the previous document, it is easier to understand the configuration.

In the configuration file, if we need to use the ip hash load balancing algorithm. We need to write a configuration similar to the following:

upstream test {    ip_hash;    server 192.168.0.1;    server 192.168.0.2;}

From the configuration, we can see the application scenarios of the Server Load balancer module: 1. The core command "ip_hash" can only be used in upstream. This command is used to notify nginx to use the ip hash load balancing algorithm. If this command is not added, nginx uses the default round robin Load Balancing module. Do you have something in common with the handler module configuration? 2. the commands in upstream {} may appear before the "server" command, after the "server" command, or between the two "server" commands. Readers may have questions. Is there any difference? Please try the following Configuration:

upstream test {    server 192.168.0.1 weight=5;    ip_hash;    server 192.168.0.2 weight=7;}

The magic thing is:

nginx: [emerg] invalid parameter "weight=7" in nginx.conf:103configuration file nginx.conf test failed

It can be seen that the ip_hash command does affect the resolution of the configuration.

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.