Skip to content

Commit

Permalink
Implement rate limit in nginx configuration (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpirix authored Jun 17, 2024
1 parent 75a5de1 commit ad7aed0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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

0 comments on commit ad7aed0

Please sign in to comment.