### HttpLimit zone
本模塊可以針對條件,進行會話的并發連接數控制。(例如:限制每個IP的并發連接數。)
__配置示例__
~~~
http {
: limit_zone one $binary_remote_addr 10m;
: ...
: server {
: ...
: location /download/ {
: limit_conn one 1;
: }
~~~
### 指令
- [#limit_zone limit_zone]
- [#limit_conn limit_conn]
### limit_zone
**語法:***limit_zone zone_name $variable the_size*
**默認值:***no*
**作用域:***http*
本指令定義了一個數據區,里面記錄會話狀態信息。
$variable 定義判斷會話的變量;the_size 定義記錄區的總容量。
例子:
~~~
limit_zone one $binary_remote_addr 10m;
~~~
定義一個叫“one”的記錄區,總容量為 10M,以變量 $binary_remote_addr 作為會話的判斷基準(即一個地址一個會話)。
您可以注意到了,在這里使用的是 $binary_remote_addr 而不是 $remote_addr。
$remote_addr 的長度為 7 至 15 bytes,會話信息的長度為 32 或 64 bytes。 而 $binary_remote_addr 的長度為 4 bytes,會話信息的長度為 32 bytes。
當區的大小為 1M 的時候,大約可以記錄 32000 個會話信息(一個會話占用 32 bytes)。
### limit_conn
**語法:***limit_conn zone_name the_size*
**默認值:***no*
**作用域:***http, server, location*
指定一個會話最大的并發連接數。 當超過指定的最發并發連接數時,服務器將返回 "Service unavailable" (503)。
例子:
~~~
limit_zone one $binary_remote_addr 10m;
: server {
: location /download/ {
: limit_conn one 1;
: }
~~~
定義一個叫“one”的記錄區,總容量為 10M,以變量 $binary_remote_addr 作為會話的判斷基準(即一個地址一個會話)。 限制 /download/ 目錄下,一個會話只能進行一個連接。 簡單點,就是限制 /download/ 目錄下,一個IP只能發起一個連接,多過一個,一律503。
### References
[原始文檔](http://sysoev.ru/nginx/docs/http/ngx_http_limit_zone_module.html "http://sysoev.ru/nginx/docs/http/ngx_http_limit_zone_module.html")
- 主要文檔
- Nginx功能概述
- 為什么選擇Nginx
- Nginx安裝
- 運行和控制Nginx
- 配置符號參考
- 優化 Nginx
- 常見問題(FAQ)
- 調試 nginx
- 核心模塊
- Nginx主模塊
- Nginx事件模塊
- 基本模塊
- http核心模塊
- HttpIndex模塊
- HttpAccess模塊
- HttpAuthBasic模塊
- HttpAutoindex模塊
- Browser模塊
- Charset模塊
- HttpEmptyGif模塊
- HttpFcgi模塊
- Geo模塊
- HttpGzip模塊
- HttpHeaders模塊
- HttpIndex模塊
- HttpReferer模塊
- HttpLimit zone
- HttpLimitReqest模塊
- HttpLog模塊
- map
- Memcached
- HttpProxy模塊
- HttpRewrite模塊
- HttpSSI模塊
- HttpUserId
- 其他模塊
- Addition模塊
- EmbeddedPerl
- flv
- HttpGzipStatic
- RandomIndex
- HttpGeoIP
- HttpRealIp
- HttpSSL
- StubStatus模塊
- HttpSubstitution
- HttpDav模塊
- GooglePerftools
- HttpXSLT
- HttpSecureLink
- HttpImageFilter
- mail模塊
- MailCore
- MailAuth
- MailProxy
- MailSSL
- 安裝
- nginx在windows上的安裝
- nginx在freebsd上的安裝
- nginx在ubuntu上的安裝
- nginx在fedora上的安裝
- nginx php-fpm安裝配置
- 配置示例和方法
- 完整例子
- 完整例子2
- 虛擬主機
- 負載均衡
- nginx防盜鏈
- HWLoadbalancerCheckErrors