This Nginx module provides rate limiting functionality implemented in Rust. It supports multiple backend storage options (Memcached, Redis, MySQL, PostgreSQL).
- IP address-based rate limiting
- Multiple storage backend support:
- Redis
- Memcached
- MySQL
- PostgreSQL
- Configurable rate limits and window sizes
- Rust 1.70 or higher
- Nginx 1.20 or higher
- One of the following storage backends:
- Redis
- Memcached
- MySQL
- PostgreSQL
- Clone the repository:
git clone https://github.com/yourusername/ngx_http_rate_limiter
cd ngx_http_rate_limiter
- Build:
cargo build --release
- Add the following to your Nginx configuration file:
load_module /path/to/libngx_http_rate_limiter.so;
http {
rate_limit_storage redis; # redis, memcached, mysql, postgresql
rate_limit_requests 100; # requests per minute
rate_limit_window 60; # window size in seconds
}
CREATE DATABASE ratelimit;
USE ratelimit;
CREATE TABLE rate_limits (
key VARCHAR(255) PRIMARY KEY,
count INT NOT NULL DEFAULT 0,
expire_at TIMESTAMP NOT NULL
);
CREATE DATABASE ratelimit;
\c ratelimit
CREATE TABLE rate_limits (
key VARCHAR(255) PRIMARY KEY,
count INT NOT NULL DEFAULT 0,
expire_at TIMESTAMP NOT NULL
);
rate_limit_storage
: Storage backend selection (redis/memcached/mysql/postgresql)rate_limit_requests
: Number of allowed requests within the specified periodrate_limit_window
: Rate limit window size in seconds
MIT