Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement rate limit in nginx configuration #413

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions dockerize/sites-enabled/prod-ssl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ upstream uwsgi {
server uwsgi:8080;
}

# Define the rate limit zone: 10 requests per second for each IP address
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;

server {
# OTF gzip compression
gzip on;
Expand Down Expand Up @@ -66,6 +69,11 @@ server {
}
# Finally, send all non-media requests to the Django server.
location / {

# Apply rate limit
limit_req zone=one burst=20 nodelay;
limit_req_status 429;

uwsgi_pass uwsgi;
# the uwsgi_params file you installed needs to be passed with each
# request.
Expand Down Expand Up @@ -184,6 +192,11 @@ server {
}
# Finally, send all non-media requests to the Django server.
location / {

# Apply rate limit
limit_req zone=one burst=20 nodelay;
limit_req_status 429;

uwsgi_pass uwsgi;
# the uwsgi_params file you installed needs to be passed with each
# request.
Expand Down
8 changes: 8 additions & 0 deletions dockerize/sites-enabled/prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ upstream uwsgi {
server uwsgi:8080;
}

# Define the rate limit zone: 10 requests per second for each IP address
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;

server {
# OTF gzip compression
gzip on;
Expand Down Expand Up @@ -63,6 +66,11 @@ server {
}
# Finally, send all non-media requests to the Django server.
location / {

# Apply rate limit
limit_req zone=one burst=20 nodelay;
limit_req_status 429;

uwsgi_pass uwsgi;
# the uwsgi_params file you installed needs to be passed with each
# request.
Expand Down