Nginx http_core_module limit_rate和limit_rate_after指令

Posted wx5bcd2f496a1cf

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx http_core_module limit_rate和limit_rate_after指令相关的知识,希望对你有一定的参考价值。


Nginx

 

官方解释


Syntax:

limit_rate rate;​

Default:

limit_rate 0;

Context:

​http​​​, ​​server​​​, ​​location​​​, ​​if in location​

Limits the rate of response transmission to a client. The ​rate​ is specified in bytes per second. The zero value disables rate limiting. The limit is set per a request, and so if a client simultaneously opens two connections, the overall rate will be twice as much as the specified limit.

Parameter value can contain variables (1.17.0). It may be useful in cases where rate should be limited depending on a certain condition:

map $slow $rate 1 4k; 2 8k; limit_rate $rate;

Rate limit can also be set in the ​​$limit_rate​​ variable, however, since version 1.17.0, this method is not recommended:

server if ($slow) set $limit_rate 4k; ...

Rate limit can also be set in the “X-Accel-Limit-Rate” header field of a proxied server response. This capability can be disabled using the ​​proxy_ignore_headers​​​, ​​fastcgi_ignore_headers​​​, ​​uwsgi_ignore_headers​​​, and ​​scgi_ignore_headers​​ directives.


Syntax:

limit_rate_after size;​

Default:

limit_rate_after 0;

Context:

​http​​​, ​​server​​​, ​​location​​​, ​​if in location​

This directive appeared in version 0.8.0.

Sets the initial amount after which the further transmission of a response to a client will be rate limited. Parameter value can contain variables (1.17.0).

Example:

location /flv/ flv; limit_rate_after 500k; limit_rate 50k;

 

Limiting Bandwidth for Particular URLs(流量限速)


If your server provides larger files (or smaller but extremely popular files, like forms or reports), it can be useful to set the maximum speed at which clients can download them. If your site is already experiencing a high network load, limiting download speed leaves more bandwidth to keep critical parts of your application responsive. This is a very popular solution used by hardware manufacturers – you may wait longer to download a 3-GB driver for your printer, but with thousands of other people downloading at the same time you’ll still able to get your download.

以上是关于Nginx http_core_module limit_rate和limit_rate_after指令的主要内容,如果未能解决你的问题,请参考以下文章

Nginx高并发设置跟压测

Nginx服务企业应用

Nginx实战|Nginx健康检查

搭建 LNMP 环境

nginx按日分割日志

Nginx常见错误与问题之解决方法技术指南