The ngx_http_upstream_module module is used to define groups of servers that can be referenced by the proxy_pass, fastcgi_pass,uwsgi_pass, scgi_pass, and memcached_pass directives.

upstream name { … }

定义后端服务器组,会引入一个新的上下文;Context: http

 
upstream httpdsrvs {
            server …
            server…
            …
}
server address [parameters]

在upstream上下文中server成员,以及相关的参数;Context: upstream

 
address的表示格式:
unix:/PATH/TO/SOME_SOCK_FILE
IP[:PORT]
HOSTNAME[:PORT]
 
parameters:
weight=number
权重,默认为1;默认算法是wrr
 
max_fails=number
失败尝试最大次数;超出此处指定的次数时,server将被标记为不可用
 
fail_timeout=time
设置将服务器标记为不可用状态的超时时长
 
max_conns
当前的服务器的最大并发连接数
 
backup
将服务器标记为“备用”,即所有服务器均不可用时此服务器才启用
 
down
标记为“不可用”

先在nginx前端配置down,然后在下架后端服务器,上架新的web程序,然后上架,在修改配置文件立马的down

least_conn

最少连接调度算法,当server拥有不同的权重时其为wlc

要在后端服务器是长连接时,效果才好,比如mysql

ip_hash

源地址hash调度方法

hash key [consistent]

基于指定的key的hash表来实现对请求的调度,此处的key可以直接文本、变量或二者的组合

作用:将请求分类,同一类请求将发往同一个upstream server

If the consistent parameter is specified the ketama consistent hashing method will be used instead.

示例:

 
hash $request_uri consistent;
hash $remote_addr;
hash $cookie_name; 

对同一浏览器的请求,发往同一个upstream server

keepalive connections

为每个worker进程保留的空闲的长连接数量

nginx的其它的二次发行版:

tengine

OpenResty

1.9版本之后可以反代tcp/udp的协议,基于stream模块,工作与传输层

本文原创地址:https://www.linuxprobe.com/nginx-tcp-modular.html作者:吴向平,审核员:逄增宝

本文原创地址:https://www.linuxprobe.com/nginx-tcp-modular.html编辑:xiangping wu,审核员:暂无