Nginx: upstream parameters 参数, 配置负载均衡时如下例:
upstream backend {
server backend1.example.com weight=5;
server 127.0.0.1:8080 max_fails=3 fail_timeout=30s;
server unix:/tmp/backend3;
}
其中可选参数为: weight=number, max_fails
=number, fail_timeout=time, backup, down;
官网文档原文:
Defines an address
and other parameters
of the server. An address can be specified as a domain name or IP address, and an optional port, or as a UNIX-domain socket path specified after the “unix:
” prefix. If port is not specified, the port 80 is used. A domain name that resolves to several IP addresses essentially defines multiple servers.
The following parameters can be defined:
weight
=number
sets a weight of the server, by default 1.
max_fails
=number
sets a number of unsuccessful attempts to communicate with the server during a time set by the fail_timeout
parameter after which it will be considered down for a period of time also set by the fail_timeout
parameter. By default, the number of unsuccessful attempts is set to 1. A value of zero disables accounting of attempts. What is considered to be an unsuccessful attempt is configured by the proxy_next_upstream, fastcgi_next_upstream, and memcached_next_upstream directives. The http_404
state is not considered an unsuccessful attempt.
fail_timeout
=time
sets
- a time during which the specified number of unsuccessful attempts to communicate with the server should happen for the server to be considered down;
- and a period of time the server will be considered down.
By default, timeout is set to 10 seconds.
backup
marks the server as a backup server. It will be passed requests when the primary servers are down.
down
marks the server as permanently down; used along with the ip_hash directive.
Example:
upstream backend {
server backend1.example.com weight=5;
server 127.0.0.1:8080 max_fails=3 fail_timeout=30s;
server unix:/tmp/backend3;
server backup1.example.com:8080 backup;
}
syntax: |
ip_hash;
|
default: |
— |
context: |
upstream
|
Specifies that a group should use a load balancing method where requests are distributed between servers based on client IP addresses. The first three octets of the client IPv4 address, or the entire IPv6 address, are used as a hashing key. The method ensures that requests of the same client will always be passed to the same server except when this server is considered down in which case client requests will be passed to another server and most probably it will also be the same server.
IPv6 addresses are supported starting from versions 1.3.2 and 1.2.2.
If one of the servers needs to be temporarily removed, it should be marked with the down
parameter in order to preserve the current hashing of client IP addresses.
Example:
upstream backend {
ip_hash;
server backend1.example.com;
server backend2.example.com;
server backend3.example.com down;
server backend4.example.com;
}
Until versions 1.3.1 and 1.2.2 it was not possible to specify a weight for servers using the ip_hash
load balancing method.
syntax: |
keepalive connections ;
|
default: |
— |
context: |
upstream
|
This directive appeared in version 1.1.4.
Activates cache of connections to upstream servers.
个人总结上面几点:
1. IPV6 从Nginx1.2.2(稳定版本)支持;
2. ip_hash 可以支持 weight参数,从Nginx1.2.2(稳定版本)支持;
3. down 只在配置ip_hash中使用;
4. max_fails和fail_timeout参数要结合使用;
5. 当一个做balance的servers配置max_fails和fail_timeout时:
当在fail_timeout的时间内,某个server连接失败了max_fails次,则nginx会认为该server不工作了.
同时,在接下来的 fail_timeout时间内,nginx不再将请求分发给失效的server.
如果超出fail_timeout后,nginx则继续把request发往该server上.
后面依次再做上面循环.
分享到:
相关推荐
这个项目旨在解决在配置Nginx时遇到的特定错误提示“nginx: [emerg] invalid parameter "srun_id=tomcat1"”。 首先,让我们深入理解Nginx的upstream模块。Nginx作为一款高性能的HTTP和反向代理服务器,经常用于...
2. 配置Nginx:在Nginx的配置文件(通常是`/etc/nginx/nginx.conf`)中,定义一个upstream块,并启用fair模块。例如: ``` upstream backend { fair; server backend1.example.com weight=5; server backend2....
此资源有两个文件,含 nginx-upstream-jvm-route 和 nginx 对应版本,都是tar.gz文件。 安装方法网上很多就不写了,亲测可用。 不用担心版本不匹配造成安装失败,再浪费积分去到处下载尝试的烦恼。 此资源有两个文件...
借助淘宝技术团队开发的nginx模快nginx_upstream_check_module来检测后方realserver的健康状态,如果后端服务器不可用,则会将其踢出upstream,所有的请求不转发到这台服务器。当期恢复正常时,将其加入upstream。 ...
官方nginx 镜像不带主动健康,本镜像将 nginx_upstream_check健康检查 打包到了镜像中。
为了实现更灵活的负载均衡策略,Nginx提供了一系列的upstream模块,其中,`nginx_upstream_hash`模块是其中的一种,用于根据请求的某些参数进行哈希计算,进而将请求定向到特定的后端服务器。本文将深入探讨`nginx_...
nginx:alpine离线镜像包,使用docker load -i nginxalpine.tar
**Nginx Upstream Check Module** 是一个由淘宝团队开发的插件,专门用于Nginx服务器,旨在增强其反向代理功能,提供对后端服务器节点的健康检查。这个模块使得运维人员能够实时监控后端服务器的状态,确保在将请求...
patch -p0 < ../nginx_upstream_check_module-master/check_1.9.2+.patch ./configure --prefix=/usr/local/nginx \ --with-http_ssl_module --with-http_stub_status_module --with-pcre \ --with-...
#### 一、启动错误:`sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory` **问题描述**: 在尝试启动Nginx时,可能会遇到如下的错误...
nginx_upstream_jvm_route 是一个 Nginx 的扩展模块,用来实现基于 Cookie 的 Session Sticky 的功能。 安装方法(进入Nginx源码目录): #patch -p0 # ./configure --prefix=/usr/nginx-0.8.1 --with-...
3. 编译并安装Nginx:`make && make install`。 4. 修改Nginx配置文件,例如`/etc/nginx/nginx.conf`,在upstream块中引入hash指令,如下所示: ``` upstream backend { hash $request_uri consistent; server ...
为了满足动态负载均衡的需求,nginx提供了丰富的upstream模块,其中,nginx_upstream_hash模块是其一,它允许我们基于特定的请求参数来分配请求到不同的后端服务器,实现更为灵活的负载策略。本文将详细介绍nginx_...
nginx_upstream_jvm_route 是一个 Nginx 的扩展模块,用来实现基于 Cookie 的 Session Sticky 的功能。 安装方法(进入Nginx源码目录): #patch -p0 # ./configure --prefix=/usr/nginx-0.8.1 --with-...
Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的,第一个公开版本0.1.0发布于2004年10月4日。 其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例...
这里我们关注的是一个包含特定模块的Nginx配置:`nginx1.16`,`nginx-upstream-check-module-master` 和 `nginx-upload-module`。这三个组件将帮助我们增强Nginx在处理后端服务健康检查、文件上传等方面的功能。 ...
《深入理解Nginx:模块开发与架构解析》是阿里巴巴资深Nginx技术专家呕心沥血之作,是作者多年的经验结晶,也是目前市场上唯一一本通过还原Nginx设计思想,剖析Nginx架构来帮助读者快速高效开发HTTP模块的图书。...
**Nginx配置Upstream负载均衡详解** 在现代Web服务架构中,负载均衡是一项至关重要的技术,它能够有效地分散网络流量,确保服务器集群的稳定性和高可用性。Nginx作为一款高性能的反向代理服务器和HTTP缓存服务器,...
`nginx-upstream-manager.zip` 提供了一个开源项目,用于更方便地管理和操作 Nginx 的 upstream 配置。 这个项目的核心是 `upstream_manager.py` 脚本,它提供了对 Nginx upstream 集群进行增删改查等操作的能力。...