Managing Rate Limiting and Bandwidth
1. Enabling Rate Limit Module
Enable the mod_ratelimit module to manage bandwidth and rate limiting in Apache HTTP Server.
| Directive | Description | Default |
|---|---|---|
| LoadModule | Loads the rate limit module | mod_ratelimit_module |
2. Setting Output Rate Limits
Configure the output rate limit to control how fast data is sent to clients.
| Directive | Description | Default |
|---|---|---|
| RateLimit | Maximum bytes per second to send | Unlimited |
| RateLimitBurst | Maximum burst size in bytes | 1024 |
Example: Set Output Rate Limit
<Location "/downloads">
RateLimit 102400
RateLimitBurst 204800
</Location>
3. Configuring Request Timeout
Set the maximum time allowed for a request to complete before being terminated.
| Directive | Description | Default |
|---|---|---|
| Timeout | Time in seconds for request timeout | 60 |
4. Setting Read Timeout
Define the maximum time to wait for data to be read from a client.
| Directive | Description | Default |
|---|---|---|
| KeepAliveTimeout | Time in seconds to wait for a new request | 5 |
| ReadTimeout | Time in seconds to wait for read operations | 60 |
5. Limiting Request Body Size
Control the maximum size of request bodies to prevent abuse or resource exhaustion.
| Directive | Description | Default |
|---|---|---|
| LimitRequestBody | Maximum size in bytes of request body | Unlimited |
6. Setting Request Line Size
Define the maximum length of an HTTP request line to prevent oversized requests.
| Directive | Description | Default |
|---|---|---|
| LimitRequestLine | Maximum length in bytes of the request line | 8190 |
7. Configuring Request Field Size
Set the maximum size of individual HTTP header fields to prevent oversized headers.
| Directive | Description | Default |
|---|---|---|
| LimitRequestFieldSize | Maximum size in bytes of a single header field | 8190 |
8. Setting Request Fields Count
Control the maximum number of headers allowed in a request to prevent header flooding.
| Directive | Description | Default |
|---|---|---|
| LimitRequestFields | Maximum number of headers in a request | 1000 |
9. Configuring Connection Limits
Manage the maximum number of concurrent connections to prevent server overload.
| Directive | Description | Default |
|---|---|---|
| MaxRequestWorkers | Maximum number of worker processes | 150 |
| ServerLimit | Maximum number of server processes | 256 |
10. Using QoS Module
Use the Quality of Service (QoS) module to prioritize traffic and manage bandwidth.
| Directive | Description | Default |
|---|---|---|
| LoadModule | Loads the QoS module | mod_qos_module |
11. Implementing Custom Rate Limiting
Create custom rate limiting rules using mod_rewrite or mod_lua for more granular control.
| Directive | Description | Default |
|---|---|---|
| RewriteRule | Define custom rate limiting logic | None |
Example: Custom Rate Limiting with RewriteRule
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^192\.168\.1\.
RewriteRule .* - [R:429,L]
</IfModule>
12. Testing Rate Limits
Verify that rate limits are working correctly using tools like curl or ab (ApacheBench).
ab or httperf to simulate high traffic and validate rate limits.