首页 > 开发 > Nginx > 正文

nginx警告the “limit_zone” directive is deprecated, use the “limit_conn_zone” directive 的问题

2020-02-10 00:18:21
字体:
来源:转载
供稿:网友

刚把nginx从1.0.15升级到了1.2.0,更新完后检测了一下配置文件。

# /ooo/nginx/sbin/nginx -t
nginx: [warn] the "limit_zone" directive is deprecated, use the "limit_conn_zone" directive instead in /ooo/nginx/conf/nginx.conf:38
nginx: the configuration file /ooo/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /ooo/nginx/conf/nginx.conf test is successful

出来了上面的警告,意思是说:limit_zone 已经弃用!该属性改成了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:

只要使用下面的方法即可:

一、在nginx.conf 中的 http {} 里写入以下代码:

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

二、然后在需要限制下载速度的站点里写入以下代码:

server {
    ...
    limit_conn perip 10;
    #指定一个会话最大的并发连接数(与之前的limit_conn_zone配合使用),可对单独目录做出限制,一个IP只能发起10个连接,多于10个,一律返回Services unavailable(503)状态,生产环境需考虑办公室或者局域网共享IP问题
    limit_rate_after 1m;
    #设置单连接限速条件(当下载文件字节数超过1MB后,limit_rate限速生效,限速100k)
    limit_rate 100k;
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表