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

[经验分享] Nginx基础配置

[复制链接]

尚未签到

发表于 2018-11-10 12:07:48 | 显示全部楼层 |阅读模式
  1.Syntax:upstream name { ... }
  Default:—
  Context:http
  Defines a group of servers. Servers can listen on different ports. In addition, servers listening on TCP and UNIX-domain sockets can be mixed.
  用于指定后端服务器组,upstream 后面为自定义的后端服务器组,默认为轮询调度对后端服务器进行转发处理请求,如果后端某一台服务器发生故障调度器服务器会自动将其从组中踢除,待恢复后又自动加回组中。
  2.Syntax:server address [parameters];
  Default:—
  Context:upstream
  Defines the address and other parameters of a server. The address can be specified as a domain name or IP address, with an optional port, or as a UNIX-domain socket path specified after the “unix:” prefix. If a port is not specified, the port 80 is used. A domain name that resolves to several IP addresses defines multiple servers at once.
  The following parameters can be defined:
  weight=number
  sets the weight of the server, by default, 1.
  max_conns=number
  该指令用于指定设置组内服务器
  address 服务器地址
  [parameters]
  weight=number
  为组内添加权重,权重值越高服务器被优先用于服务器,组内权重默认为1,如果不设置则组内主句轮询处理;
  max_fails=number
  设置一个请求失败的次数,在一定时间范围内当对组内服务器请求失败可允许超过次数,如果请求失败次数超过该值时则认为该服务器为无效,默认值也是为1,
  fail_timeout=number
  该时间设置有两个作用。一是当多长时间尝试去连接已失效服务器,第二个是在max_fails里面说到的在一定时间内对组内服务器请求失败的时间;默认为1;
  backup ;
  将组内某台服务器设置为备用服务器,只有所有服务器都处于无效情况下,该服务器才会被用来处理请求
  down;
  将组内某台服务器设置为永久无效状态。
  示例:
  http {
  upstream baks {
  server 10.1.45.61:80 weight=1 max_fails=2 fail_timeout=30s;
  server 10.1.45.62:80 weight=3;
  server 127.0.0.1:80 backup;
  }
  }
  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.
  该指令用于实现会话保持功能,将来自于某一客户端的请求定向到组内任何一台服务器上,保证客户端与服务器之间建立稳定的会话,只有在该服务器在无效情况下才会被下一个服务器接收和处理
  实例如下:
  http {
  ip_hash;
  upstream baks {
  server 10.1.45.61:80 weight=1 max_fails=2 fail_timeout=30s;
  server 10.1.45.62:80 weight=3;
  server 127.0.0.1:80 backup;
  }
  }
  4.Syntax:keepalive connections;
  Default:—
  Context:upstream
  This directive appeared in version 1.1.4.
  Activates the cache for connections to upstream servers.

  The connections parameter sets the maximum number of>  该指令用于设置为每个worker进程保留的空闲的长连接数量。
  5.Syntax:least_conn;
  Default:—
  Context:upstream
  This directive appeared in versions 1.3.1 and 1.2.2.
  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.
  最少连接调度算法,当server拥有不同的权重时其为wlc;
  6.Syntax:hash key [consistent];
  Default:—
  Context:upstream
  This directive appeared in version 1.7.2.
  Specifies a load balancing method for a server group where the client-server mapping is based on the hashed key value. The key can contain text, variables, and their combinations. Note that adding or removing a server from the group may result in remapping most of the keys to different servers. The method is compatible with the Cache::Memcached Perl library.
  If the consistent parameter is specified the ketama consistent hashing method will be used instead. The method ensures that only a few keys will be remapped to different servers when a server is added to or removed from the group. This helps to achieve a higher cache hit ratio for caching servers. The method is compatible with the Cache::Memcached::Fast Perl library with the ketama_points parameter set to 160.
  基于指定的key的hash表来实现对请求的调度,此处的key可以直接文本、变量或二者的组合;
  作用:将请求分类,同一类请求将发往同一个upstream server;


运维网声明 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-633225-1-1.html 上篇帖子: Nginx+Apache环境 下篇帖子: Nginx支持php配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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