nginx学习(六)——nginx的配置系统3之upstream_module(上)
来源:互联网 发布:java编程心得体会 编辑:程序博客网 时间:2024/06/08 10:20
upstream
upstream backend { server backend1.example.com weight=5; server backend2.example.com:8080; server unix:/tmp/backend3; server backup1.example.com:8080 backup; server backup2.example.com:8080 backup;}server { location / { proxy_pass http://backend; }}
weight=number
设置某个服务器的权重,默认为1.max_fails=number
fail_timeout=time
and the period of time the server will be considered unavailable.
By default, the parameter is set to 10 seconds.
backup
down
ip_hash
keepalive
Activates the cache for connections to upstream servers.The connections parameter sets the maximum number of idle keepalive connections to upstream servers that are preserved in the cache of each worker process. When this number is exceeded, the least recently used connections are closed.
It should be particularly noted that the keepalive directive does not limit the total number of connections to upstream servers that an nginx worker process can open. The connections parameter should be set to a number small enough to let upstream servers process new incoming connections as well.
Example configuration of memcached upstream with keepalive connections:
upstream memcached_backend { server 127.0.0.1:11211; server 10.0.0.2:11211; keepalive 32;}server { ... location /memcached/ { set $memcached_key $uri; memcached_pass memcached_backend; } server { ... location /http/ { proxy_pass http://http_backend; proxy_http_version 1.1; proxy_set_header Connection ""; ... }}
For HTTP, the proxy_http_version directive should be set to “1.1” and the “Connection” header field should be cleared:
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version
Sets the HTTP protocol version for proxying. By default, version 1.0 is used. Version 1.1 is recommended for use with keepalive connections and NTLM authentication.
启动upstream服务器的连接缓存。该参数设置了每个worker进程缓存的最大的空闲“长连接”个数。当超过该值之后,根据LRU算法关闭对应的长连接。
需要特别注意的是,该参数不会限制一个nginx worker进程可以打开的总连接数。这个参数应该设置的足够小,以便于让upstream服务器也能够处理建立新的连接来处理新的请求(长连接是在同一个连接上执行多个请求)。
如果是keepAlive connections(长连接),proxy_http_version推荐使用1.1。
least_conn
Specifies that a group should use a load balancing method where a request is passed to the server with the least number of active connections, taking into account weights of servers. If there are several such servers, they are tried in turn using a weighted round-robin balancing method.
请求会被分发到拥有最少活跃连接数的服务器上(服务器当前正在处理请求的连接数或者长连接数最少)在考虑权证的情况下。如果有多个这样的服务器,那么就按照权重的轮训机制来分发请求。
least_time
Specifies that a group should use a load balancing method where a request is passed to the server with the least average response time and least number of active connections, taking into account weights of servers. If there are several such servers, they are tried in turn using a weighted round-robin balancing method.
请求会被分发给平均响应时间最小的服务器。
nginx还有很多的配置,需要用到的时候可以查看nginx网站上的文档。
Alphabetical index of directives
- nginx学习(六)——nginx的配置系统3之upstream_module(上)
- nginx学习(七)——nginx的配置系统3之upstream_module(下)
- nginx学习(八)——nginx的配置系统4之healthcheck module
- nginx学习(九)——nginx的配置系统5之rewrite
- nginx学习(十)——nginx的配置系统6之server_name
- nginx学习(十一)——nginx的配置系统7之if
- nginx学习(五)——nginx的配置系统1
- nginx学习(五)——nginx的配置系统2
- Nginx学习总结(3)——Nginx配置及应用场景之高级配置
- Nginx学习笔记1—Nginx(Win32) 配置详解
- Nginx学习笔记1—Nginx(Win32) 配置详解
- nginx源码学习(六)
- nginx学习之旅(二)nginx 配置初探
- Nginx学习笔记(六):怎样使用HTTP配置(下)
- nginx 源码学习笔记(六)——nginx基本数据结构
- nginx 源码学习笔记(六)——nginx基本数据结构
- Nginx学习——Nginx基本配置
- nginx学习总结三(nginx的基本配置)
- 回校毕社(一)
- TortoiseGit上传代码到GitHub记录
- [Lintcode]Count of Smaller Number
- Linux free命令
- bool operator
- nginx学习(六)——nginx的配置系统3之upstream_module(上)
- 第三周项目1-顺序表的基本运算
- 剩余文件数目
- 新人求助各路大神,cocos EditBox 旋转之后无法输入的问题
- 基于数组的栈
- 叨叨原型图
- ExpandableListView 去掉默认箭头,设置成别的图片
- 【cocos2d-x 】解决scrollview上的menu拖动问题以及menu item在可视区外仍能触发的问题
- 建造者模式