当前位置: 首页 > Web与应用 > 正文

nginx自从1.1.8版本发布后将limit_conn更换为limit_conn_zone 。对应则需要修改配置文件。

官方公告:

syntax:  limit_zone name $variable size;

default:  —
context:  http

This directive is made obsolete in version 1.1.8, an equivalent limit_conn_zone directive with a changed syntax should be used instead:

limit_conn_zone $variable zone=name:size;

limit_conn_zone的描述:

When several limit_conn directives are specified, any configured limit will apply. For example, the following configuration will limit the number of connections to the server per client IP and at the same time will limit the total number of connections to the virtual host:

limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;

server {

limit_conn perip 10;
limit_conn perserver 100;
}

These directives are inherited from the previous level if and only if there are no limit_conn directives on the current level.

 

对应conf文件夹中的nginx.conf文件,将limit_conn替换为limit_conn_zone。使用于http

示例:

limit_conn_zone $binary_remote_addr zone=perip:10m;  #容器共使用10M的内存来对于IP传输开销

 

对应的虚拟主机文件,将原来的limit_conn one 替换为 limit_conn perip。使用于server

示例:

limit_conn perip 10;  # 每个IP使用10个连接。

 

[分享]nginx 新语法 limit_conn_zone 替换 limit_conn 用法:目前有 3 条评论

  1. 地板
    xjdtd

    我用的nginx1.9.5 测试限制一个IP的连接数,不成功(没起作用),不知道怎么回事?

    limit_conn_zone $binary_remote_addr zone=perip:10m;
    limit_conn_log_level info;

    server{
    listen 8911;
    location /test{
    limit_conn perip 1;

  2. 板凳
    xjdtd

    [root@zabbix-112 ~]# /usr/local/src/http_load-14aug2014/http_load -rate 30 -f 300 /usr/local/src/http_load-14aug2014/url.txt
    300 fetches, 1 max parallel, 3600 bytes, in 9.90162 seconds
    12 mean bytes/connection
    30.2981 fetches/sec, 363.577 bytes/sec
    msecs/connect: 0.615367 mean, 4.818 max, 0.267 min
    msecs/first-response: 0.665823 mean, 4.461 max, 0.294 min
    HTTP response codes:
    code 200 — 300 没起作用

  3. 沙发
    xjdtd

    有知道的朋友,请发送xjdtd@163.com 非常感谢!

发表评论