设为首页 收藏本站
查看: 617|回复: 0

[经验分享] 详细解释:nginx中ChsHttpUpstreamModule模块配置及各个参数含义

[复制链接]

尚未签到

发表于 2016-12-28 11:09:37 | 显示全部楼层 |阅读模式
  该模块为后端服务器提供简单的负载均衡(轮循调度和客户端 IP)。
  示例:

upstream backend  {
server backend1.example.com weight=5;
server backend2.example.com:8080;
server unix:/tmp/backend3;
}
server {
location / {
proxy_pass  http://backend;
}
}
  
指令:
  ip_hash
语法: ip_hash
  默认值: 无
  语境: upstream
  This directive causes requests to be distributed between upstreams based on the IP-address of the client.


The key for the hash is the class-C network address of the client. This method guarantees that the client request will always be transferred to the same server. But if this server is considered inoperative, then the request of this client will be transferred
to another server. This gives a high probability clients will always connect to the same server.
  It is not possible to combine ip_hash and weight methods for connection distribution. If one of the servers must be removed for some time, you must mark that server as *down*.
  示例:

upstream backend {
ip_hash;
server   backend1.example.com;
server   backend2.example.com;
server   backend3.example.com  down;
server   backend4.example.com;
}

  server
语法: server name [parameters]
  默认值: 无
  语境: upstream
  Directive assigns the name and the parameters of server. For the name it is possible to use a domain name, an address, port or unix socket. If domain name resolves to several addresses, then all are used.
  weight = NUMBER - set weight of the server, if not set weight is equal to one.

max_fails = NUMBER - number of unsuccessful attempts at communicating with the server within the time period (assigned by parameter fail_timeout) after which it is considered inoperative. If not set, the number of attempts is one. A value of 0 turns off this
check. What is considered a failure is defined by proxy_next_upstream or fastcgi_next_upstream (except http_404 errors which do not count towards max_fails).

fail_timeout = TIME - the time during which must occur *max_fails* number of unsuccessful attempts at communication with the server that would cause the server to be considered inoperative, and also the time for which the server will be considered inoperative
(before another attempt is made). If not set the time is 10 seconds. fail_timeout has nothing to do with upstream response time, use proxy_connect_timeout and proxy_read_timeout for controlling this.

down - marks server as permanently offline, to be used with the directive ip_hash.

backup - (0.6.7 or later) only uses this server if the non-backup servers are all down or busy

示例:

upstream  backend  {
server   backend1.example.com    weight=5;
server   127.0.0.1:8080          max_fails=3  fail_timeout=30s;
server   unix:/tmp/backend3;
}

  upstream
语法: upstream name { ... }
  默认值: 无
  语境: http
  这个指令描述了一个服务器的集合,该集合可被用于 proxy_pass 和 fastcgi_pass 指令中,作为一个单独的实体。
  这些服务器可以是监听在不同的端口,另外,并发使用同时监听 TCP 端口和 Unix 套接字的服务器是可能的。
  这些服务器能被分配不同的权重。如果没有指定,则都为一。
  示例:

upstream backend {
server backend1.example.com weight=5;
server 127.0.0.1:8080       max_fails=3  fail_timeout=30s;
server unix:/tmp/backend3;
}

  

Requests are distributed according to the servers in round-robin manner with respect of the server weight.

For example of every 7 seven requests given above they will be distributed like this: 5 requests on backend1.example.com and one request to the second and the third of server. If with an attempt at the work with the server error occurred, then the request will
be transmitted to the following server and then until all workers of server not are tested. If successful answer is not succeeded in obtaining from all servers, then to client will be returned the result of work with the last server.
  变量:
  自版本 0.5.18 之后,可通过 log_module 模块将变量值写入日志。
  示例:

log_format timing '$remote_addr - $remote_user [$time_local]  $request '
'upstream_response_time $upstream_response_time '
'msec $msec request_time $request_time';
log_format up_head '$remote_addr - $remote_user [$time_local]  $request '
'upstream_http_content_type $upstream_http_content_type';

  
$upstream_addr
Address of the upstream server that handled the request
  $upstream_cache_status
Appeared in 0.8.3. Possible values:
  MISS

EXPIRED - expired, request was passed to backend

UPDATING - expired, stale response was used due to proxy/fastcgi_cache_use_stale updating

STALE - expired, stale response was used due to proxy/fastcgi_cache_use_stale

HIT
$upstream_status
Upstream server status of the answer
  $upstream_response_time
Response time in milliseconds. Several answers are divided by commas and colons.
  $upstream_http_$HEADER
Arbitrary HTTP protocol headers, for example:

$upstream_http_host
  

原始俄文文档:http://sysoev.ru/nginx/docs/http/ngx_http_upstream.html
  原始英文wiki文档:http://wiki.nginx.org/NginxHttpUpstreamModule

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-320664-1-1.html 上篇帖子: nginx的upstream目前支持的几种分配(调度,分派)方式 下篇帖子: Nginx源码完全注释(3)ngx_list.h / ngx_list.c
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表