Nginx Load Balancing
Nginx Syntax:
Syntax: upstreamname {...}
Default :-
Context: http
Upstream definition of Server Load balancer
Name indicates the backup server
Definesagroupofservers. Serverscanlistenondifferentports. Inaddition, serverslisteningonTCPandUNIX-domainsocketscanbemixed.
Example:
Upstreambackend {
Serverbackend1.example. comweight = 5;
Server127.0.0.1: 8080max_fails = 3fail_timeout = 30 s;
Serverunix:/tmp/backend3;
}
ExampleConfiguration
Upstreambackend {
Serverbackend1.example. comweight = 5;
Serverbackend2.example.com: 8080;
Serverunix:/tmp/backend3;
Serverbackup1.example.com: 8080 backup;
Serverbackup2.example.com: 8080 backup;
}
Server {
Location /{
Proxy_passhttp: // backend;
}
}
Weight = number
Set the server weight. The default value is 1.
Max_fails = number
Set the number of failed attempts to communicate with the server. If the number of failures reaches this value within the time period defined by the fail_timeout parameter, Nginx considers the server unavailable. The server will not try again in the next fail_timeout period. The default number of failed attempts is 1. If it is set to 0, the number of attempts will be stopped and the server is always available. You can configure failed attempts by using commands proxy_next_upstream, fastcgi_next_upstream, and memcached_next_upstream. By default, the http_404 status is not considered a failed attempt.
Fail_timeout = time
Set
Time period for counting the number of failed attempts. During this period, if the number of failed attempts reaches the specified number of attempts, the server is considered unavailable.
The time period when the server is considered unavailable.
By default, the timeout value is 10 seconds.
Backup
Mark as a backup server. When the master server is unavailable, the request will be sent to these servers.
Example:
Nginx acts as the proxy server and serves as the Server Load balancer for the backend two apache servers. Its front-end IP address is 192.168.255.200's backend IP address 192.168.30.200, and server1 is the apache server IP address 192.168.30.100. Its weight is 1 ,. Server2 is the IP address of the apache server 192,. 168.30.101, and the weight is 2.
Upstreambackend {
Server192.168.30.100weight = 1;
Server192.168.30.101weight = 2;
}
Server {
Location /{
Proxy_passhttp: // backend;
}
}
:
650) this. width = 650; "title =" image 1.png "src =" http://www.bkjia.com/uploads/allimg/131228/0453121555-0.png "alt =" 17371120.png"/>
The content of inndex. php In the main directory of the site in Server1 is myweight = 1
The content of inndex. php In the main directory of the site in Server2 is myweight = 2.
When the front-end address 192.168.20.200 of nginx is accessed, it will be proxy to server1 and server2, and the weight of server is 1. So when the user requests to connect to nginx for the first time, the displayed page is the content of the home page under the Home Directory of the sever1 site. The weight of Server2 is 2. When the user connects to nginx for the second and third requests, the displayed page will be sever, and the content of the homepage under the Home Directory of Site 2.
This article is from "My blog" blog, please be sure to keep this source http://7615912.blog.51cto.com/7605912/1302293