发布于 2016-09-16 04:46:50 | 309 次阅读 | 评论: 1 | 来源: PHPERZ

这里有新鲜出炉的Nginx开发从入门到精通,程序狗速度看过来!

Nginx WEB服务器

Nginx 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。


问题描述

刚把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;
}


最新网友评论  共有(1)条评论 发布评论 返回顶部
reulxf 发布于2016-10-01 23:37:55
网上看了好多解释,感觉这个解释最容易懂,感谢~~
支持(0)  反对(0)  回复

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务