A Traefik middleware plugin that rate limits incoming requests using the GCRA algorithm and Redis as a storage backend.
Traefik Rate Limit is a middleware plugin for Traefik that limits the number of requests from a specific IP address within a defined time period. It utilizes the GCRA (Generic Cell Rate Algorithm) algorithm and Redis for storing rate limiting data, ensuring consistency across multiple Traefik instances.
X-Forwarded-For)The easiest way to install this plugin is through the Traefik Plugin Catalog.
Add the plugin to your Traefik static configuration:
experimental:plugins:traefik-rate-limit:moduleName: github.com/zekihan/traefik-rate-limitversion: v0.2.1
# Static configurationexperimental:plugins:traefik-rate-limit:moduleName: github.com/zekihan/traefik-rate-limitversion: v0.2.1
# Dynamic configurationhttp:middlewares:rate-limit:plugin:traefik-rate-limit:redis:host: redisport: 6379rateLimit:rate: 100burst: 200period: 1mipResolver:header: X-Real-IPuseSrcIP: falsewhitelistedIPNets:- "127.0.0.1/32"whitelistLocalIPs: truelogLevel: info
| Option | Type | Default | Description |
|---|---|---|---|
redis.host | string | localhost | The hostname or IP address of your Redis server. |
redis.port | int | 6379 | The port number of your Redis server. |
redis.prefix | string | traefik | The prefix for the Redis keys. |
rateLimit.rate | int | 100 | The number of requests allowed per period. |
rateLimit.burst | int | 200 | The maximum number of requests that can be made in a short period of time. |
rateLimit.period | string | 1m | The time interval for the rate limit (e.g., 1s, 1m, 1h). |
ipResolver.header | string | "" | The header to use to resolve the client IP address. If empty, the source IP is used. |
ipResolver.useSrcIP | boolean | true | Whether to use the source IP address of the request. |
whitelistedIPNets | array of strings | [] | A list of IP addresses or CIDR ranges that are not rate limited. |
whitelistLocalIPs | boolean | true | Whether to whitelist local IP ranges. |
logLevel | string | info | Log level (debug, info, warn, error) |
socketPath | string | "" | The path to the socket file for Redis. If empty, the default Redis socket is used. |
ipResolver.429 Too Many Requests error is returned.A Docker Compose setup is provided in the testing folder to test the plugin locally:
cd testingdocker-compose up -d
go test ./...
This project is licensed under the MIT License - see the LICENSE file for details.