Apache自带限速模块mod_ratelimit

-- TOC --

网站只有1M的带宽,如果提供大文件的下载,基本上在下载期间,网页就打不开了。所以有必要对可以下载的资源文件进行限速(访问网页不限速)。正好,Apache自带了一个模块,叫做mod_ratelimit,虽然不完美,但可以勉强先用用。

Provides a filter named RATE_LIMIT to limit client bandwidth. The throttling is applied to each HTTP response while it is transferred to the client, and not aggregated at IP/client level. The connection speed to be simulated is specified, in KiB/s, using the environment variable rate-limit.

mod_ratelimit提供了一个过滤器叫做RATE_LIMIT,用来限制客户带宽。限制应用在每个HTTP给客户传输回应数据时,而不是在IP层面。(也就是说,如果同一个IP多个HTTP连接,只针对每个HTTP进行限制)

Optionally, an initial amount of burst data, in KiB, may be configured to be passed at full speed before throttling to the specified rate limit. This value is optional, and is set using the environment variable rate-initial-burst.

还有一个可选项,初始的burst速率,也是以KiB为配置单位。

打开mod_ratelimit模块:

LoadModule ratelimit_module modules/mod_ratelimit.so

mod_ratelimit配置举例:

<Location "/downloads">
    SetOutputFilter RATE_LIMIT
    SetEnv rate-limit 400 
    SetEnv rate-initial-burst 512
</Location>

在/downloads目录下设置RATE_LIMIT过滤器,每个HTTP限速400KiB,初始burst速率为512KiB。

rate-initial-burst从apache 2.4.24版本开始支持。

本文链接:https://cs.pynote.net/net/httpd/202204054/

-- EOF --

-- MORE --