Nginx Server Load balancer Configuration

Source: Internet
Author: User
Tags nginx server

Nginx Server Load balancer Configuration

There are many Load Balancing Methods for WEB Services, but using Nginx for load balancing deployment is undoubtedly very efficient and very popular.

I do most of it myself.. NET development, but the deployment load has been using Nginx, and there is not much research on other load methods, only tested once using Server Farm for load deployment, not in practice in the actual project, recently, I have seen my colleagues use Server Farm for load configuration, but I do not know much about its performance. I hope you will leave a message to discuss it.

Take a look at the steps below:

1. Install and deploy the Nginx Service

See the Nginx service Introduction above.

2. Write the configuration file

Open the Vhost directory under the Nginx installation directory (this directory is already in Nginx. conf is included. If it is only for a directory load of a site, you can modify the include path.) Create the load configuration file testfz. conf. The content is as follows:

Upstream backend
{
Server 192.168.1.106: 8001 weight = 1;
Server 192.168.1.107: 8001 weight = 2;
# Ip_hash;
}

Server
{
Listen 80;
Server_name www.test.com;
Location ~ ^ /*
{
Proxy_set_header Host $ host;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
Proxy_buffering off;
Proxy_pass http: // wwwbackend;
}
}

3. Test

./Nginx-t
The following information is returned, indicating that the parameter configuration is correct.
Nginx: the configuration file/usr/local/nginx/conf/nginx. conf syntax is OK
Nginx: configuration file/usr/local/nginx/conf/nginx. conf test is successful

4. Reload the configuration file

/Etc/init. d/nginx reload

If a PID error is reported during restart, reload the configuration file in-C under the installation path.

5. Nginx configuration parameters

A. Round-Robin requests are distributed to different backend servers sequentially according to the order in the Nginx configuration file. If the server goes down, it will be automatically identified and removed;
B. weight Nginx distributes more requests to high-configuration backend servers based on the weight configuration, and distributes fewer requests to low-configuration servers.
C. ip_hash each request is allocated according to the hash result of the access ip address, ensuring that the request is connected to a fixed load server. This method can solve the session problem;
D. The minimum number of connections can forward Web requests to servers with the least number of connections. You only need to add the least_conn section.

In addition, the following configurations can be made for each server load:
A. down: The current server is not involved in the load;
B. 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;
C. fail_timeout: The pause time after max_fails fails;
D. backup: All other non-backup machines start to request backup machines only when they are down or busy. Failover can be performed.

For more Nginx tutorials, see the following:

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:

Related Article

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.