nginx模块之ngx_http_upstream_module

说明:将多个后端主机定义为服务器组,而后可由proxy_pass,fastcgi_pass,uwsgi_pass,scgi_pass和memcached_pa​​ss进行调用

1.定义后端服务器组
Syntax: upstream name { ... }
Default:
Context: http
说明:
定义一组服务器。服务器可以在不同端口上侦听。


2.定义服务器的地址和相关的参数
Syntax: server address [parameters];
Default:
Context: upstream

地址格式:
IP[:port]
HOSTNAME[port]

参数:
weight=number:服务器权重
max_conns=number:最大连接次数
max_fails=number:最大失败重试次数
fail_timeout=time:设置服务器被识别为不可用超时时长
backup:备用主机
down:标记该服务器不可用

演示:
配置nginx负载均衡
编辑/etc/nginx/nginx.conf
upstream websrvs {
server 192.168.80.11:80 weight=1;
server 192.168.80.12:80 weight=1;
}

在server中指定:
proxy_pass http://websrvs

3.源地址哈希调度算法
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 from the same client
will always be passed to the same server except when this server is unavailable.
In the latter case client requests will be passed to another server. Most probably,
it will always be the same server as well.

4.最少连接调度算法
Syntax: least_conn;
Default:
Context: upstream


5.保持连接
Syntax: keepalive connections;
Default:
Context: upstream
作用:节约套接字
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值