剛把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;
}
新聞熱點
疑難解答