本文主要解析一下ngx_http_core_module、ngx_http_limit_conn_module以及ngx_http_limit_req_module中的limit相关配置参数。

limit_rate

名称 默认配置 作用域 官方说明 中文解读 模块
limit_rate limit_rate 0; http, server, location, if in location Limits the rate of response transmission to a client. The rate is specified in bytes per second. The zero value disables rate limiting. The limit is set per a request, and so if a client simultaneously opens two connections, the overall rate will be twice as much as the specified limit. 指定每秒该连接能下载的bytes,主要用来限制个别请求的带宽 ngx_http_core_module
limit_rate_after limit_rate_after 0; http, server, location, if in location Sets the initial amount after which the further transmission of a response to a client will be rate limited. 设置多少bytes过后将启动limit计数,如果小于此值则不限速 ngx_http_core_module
limit_except 没有默认值 location Limits allowed HTTP methods inside a location. The method parameter can be one of the following: GET, HEAD, POST, PUT, DELETE, MKCOL, COPY, MOVE, OPTIONS, PROPFIND, PROPPATCH, LOCK, UNLOCK, or PATCH. Allowing the GET method makes the HEAD method also allowed 设置除了指定的http methods外其他method将被限制,允许GET就自动允许HEAD方法 ngx_http_core_module
  • 实例
        location /downloads {limit_rate_after 1m;limit_rate 500k;}location / {proxy_pass http://localhost:3000;limit_except GET {deny all;}}
复制代码

limit_conn

名称 默认配置 作用域 官方说明 中文解读 模块
limit_conn 没有默认值,语法 limit_conn zone number; http, server, location Sets the shared memory zone and the maximum allowed number of connections for a given key value. When this limit is exceeded, the server will return the error in reply to a request. 指定一个zone的每个key最大连接数 ngx_http_limit_conn_module
limit_conn_zone 没有默认值,语法 limit_conn_zone key zone=name:size; http Sets parameters for a shared memory zone that will keep states for various keys. In particular, the state includes the current number of connections. The key can contain text, variables, and their combination. Requests with an empty key value are not accounted. 第一个参数是key,第二个参数是指定zone及其存放元数据(key,current num of conns per key,zone size)的共享内存大小 ngx_http_limit_conn_module
limit_conn_log_level limit_conn_log_level error; http, server, location Sets the desired logging level for cases when the server limits the number of connections. This directive appeared in version 0.8.18. 指定当触发limit的时候日志打印级别 ngx_http_limit_conn_module
  • 实例
http {limit_conn_zone $binary_remote_addr zone=ips:10m;limit_conn_zone $server_name zone=servers:10m;limit_conn_log_level notice;server {# these limits apply to the whole virtual serverlimit_conn ips 10;# only 1000 simultaneous connections to the same server_namelimit_conn servers 1000;}
}
复制代码

limit_req

名称 默认配置 作用域 官方说明 中文解读 模块
limit_req 没有默认值,语法 limit_req zone=name [burst=number] [nodelay]; http, server, location Sets the shared memory zone and the maximum burst size of requests. If the requests rate exceeds the rate configured for a zone, their processing is delayed such that requests are processed at a defined rate. Excessive requests are delayed until their number exceeds the maximum burst size in which case the request is terminated with an error. 指定zone的burst大小 ngx_http_limit_req_module
limit_req_zone 没有默认值,语法 limit_req_zone key zone=name:size rate=rate; http Sets parameters for a shared memory zone that will keep states for various keys. In particular, the state stores the current number of excessive requests. The key can contain text, variables, and their combination. Requests with an empty key value are not accounted. 第一个参数指定key,第二个参数指定zone名称和元数据的内存大小,第三个参数rate指定单位时间的请求数阈值 ngx_http_limit_req_module
limit_req_log_level limit_req_log_level error; http, server, location Sets the desired logging level for cases when the server refuses to process requests due to rate exceeding, or delays request processing. Logging level for delays is one point less than for refusals. 指定触发req limit时打印的日志级别 ngx_http_limit_req_module
  • 实例
http {limit_req_zone $binary_remote_addr zone=myreqzone:10mlimit_req_log_level warn;server {## 每个ip限定10个连接数## 正常一个浏览器给每个host开两到三个连接## 触发的话会返回503## nodelay表示一上来就直接计算,不经过一些预热后再计算limit_req zone=myreqzone burst=10 nodelay;}
}
复制代码

doc

  • ngx_http_core_module
  • ngx_http_limit_conn_module
  • ngx_http_limit_req_module

nginx limit配置参数解读相关推荐

  1. kube-controller-manager 配置参数解读

    下面是kube-controller-manager version 1.12.0的所有配置,其中高亮加粗的是我认为需要注意的Flag. Flag Comments –allocate-node-ci ...

  2. nginx proxy cache配置参数解读

    为什么80%的码农都做不了架构师?>>>    序 本文主要解析一下nginx ngx_http_proxy_module中的cache相关配置参数. proxy_cache 名称 ...

  3. Spring Cloud Alibaba - 09 Ribbon 饥饿加载及其他配置参数解读

    文章目录 解决Ribbon 第一次调用耗时高的配置 超时时间相关参数 并发参数 重试 源码 解决Ribbon 第一次调用耗时高的配置 开启饥饿加载 # ribbon 饥饿加载 解决第一次耗时多的问题 ...

  4. php+php-fom+nginx配置参数调优详解

    文章目录 一.前言 1.mysql配置参数: 2.注意 二.php参数配置及讲解 1.phpini的基本设置 2.php参数设置 三.php-fpm设置 1.设置子进程数,增加并发量 2.防止频繁出现 ...

  5. Zookeeper配置参数与节点值的解读

    配置参数解读 Zookeeper中的配置文件zoo.cfg中参数含义解读如下: 1.tickTime =2000:通信心跳数,Zookeeper服务器与客户端心跳时间,单位毫秒 Zookeeper使用 ...

  6. 三、nginx服务的nginx.conf的参数配置解析

    前一篇:二.nginx服务的nginx.conf配置参数解析 后一篇:四.nginx服务器的参数配置解析 目录 一.虚拟主机设定模块 1.upstream模块配置样式 1.1.默认配置 1.2.wei ...

  7. zookeeper中配置参数结实

    Zookeeper中的配置文件zoo.cfg中参数含义解读如下: 1)tickTime =2000:通信心跳数,Zookeeper服务器与客户端心跳时间,单位毫秒 Zookeeper使用的基本时间,服 ...

  8. Nginx网站服务(安装nginx,nginx访问配置)

    目录 一,nginx概述 1,什么是nginx? 2,Nginx应用场景 3.,Nginx的httpd七层代理和四层代理 二,Nginx和Apache的区别 三,手工编译安装nginx服务 1,关闭防 ...

  9. nginx配置参数详解

    PS:Nginx使用有两三年了,现在经常碰到有新用户问一些很基本的问题,我也没时间一一回答,今天下午花了点时间,结合自己的使用经验,把Nginx的主要配置参数说明分享一下,也参考了一些网络的内容,这篇 ...

  10. 史上最全的Nginx配置参数中文说明

    Nginx配置参数中文详细说明: #定义Nginx运行的用户和用户组 user www www; # #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; # # ...

最新文章

  1. Collection集合List、Set
  2. 常用小功能(打电话、发短信、发邮件)
  3. 网站优化还是需要从实际工作经验中总结优化技巧
  4. linux ubuntu 切换到超级用户失败的解决办法(su 认证失败)
  5. [数据结构考前必看]中缀表达式转化成后缀表达式_例题超多+分步骤讲解+带你手算
  6. protocol buffer没那么难,不信你看这篇
  7. 虚拟化精华问答 | 虚拟化会使管理更轻松吗?
  8. matlab中tsne函数,t-Distributed Stochastic Neighbor Embedding
  9. 大数据学习系列----大数据项目的思考
  10. keil5安装_Keil 5安装教程
  11. 阿里巴巴 程劭非(寒冬)- 《浅谈前端交互的基础设施的建设》
  12. 重置Winsock2
  13. Puppet erb模板介绍(三十二)
  14. Jumping NLP Curves: A review of NLP research (翻译)
  15. redis服务之主从复制、哨兵模式、群集模式
  16. Python练习--模仿王者荣耀定义两个英雄类
  17. 2022微软实习面经 | 关于实习面试的所有问题,都能在这里找到答案
  18. 多路PT100转RS485模块
  19. 专访SegmentFault开发团队:垂直问答社区的架构升级
  20. 【融职培训】Web前端学习 第2章 网页重构7 浮动布局

热门文章

  1. Atiti 重定向标准输出到字符串转接口adapter stream流体系 以及 重定向到字符串
  2. paip.提升用户体验---c++ qt自定义窗体(1)---标题栏的绘制
  3. paip.设置鼠标灵敏度API
  4. 董承非: 如何从各种类型的错误中学习
  5. PPT好帮手,模版不用愁-www.officeplus.cn
  6. 云原生时代,分布式系统设计必备知识图谱(内含22个知识点)
  7. 宝藏女孩程序媛,谈谈职场成长这些事
  8. eBPF技术应用云原生网络实践:kubernetes网络 | 凌云时刻
  9. 【热聘】蚂蚁金服-系统软件和安全资深/高级/专家/工程师
  10. 【优化算法】混沌博弈优化算法(CGO)【含Matlab源码 1803期】