From 29f185adcf246c475096e7864fcd552172b8ed67 Mon Sep 17 00:00:00 2001 From: Redume Date: Sun, 17 Nov 2024 14:53:13 +0300 Subject: [PATCH] feat: Made rate limit via nginx --- nginx.conf | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/nginx.conf b/nginx.conf index b6fd6e7..b2ecc46 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,6 +1,9 @@ events { } http { + limit_req_zone $binary_remote_addr zone=kekkai:10m rate=10r/s; + # Change the number '10' to your own, to change the threshold number for rate limit + upstream server_backend { server server:3000; } @@ -13,8 +16,11 @@ http { listen 80; server_name localhost; # Your domain + limit_req zone=kekkai; location / { + limit_req zone=kekkai burst=4; + proxy_pass http://server_backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -23,6 +29,8 @@ http { } location /api/configuration { + limit_req zone=kekkai burst=4; + proxy_pass http://server_backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -31,6 +39,8 @@ http { } location /api/getChart { + limit_req zone=kekkai burst=4; + proxy_pass http://chart_backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -39,6 +49,8 @@ http { } location /static/chart { + limit_req zone=kekkai burst=4; + proxy_pass http://chart_backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -54,7 +66,11 @@ http { ssl_certificate /etc/nginx/ssl/fullchain.pem; ssl_certificate_key /etc/nginx/ssl/privkey.pem; + limit_req zone=kekkai; + location / { + limit_req zone=kekkai burst=4; + proxy_pass http://server_backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -63,6 +79,8 @@ http { } location /api/configuration { + limit_req zone=kekkai burst=4; + proxy_pass http://server_backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -71,6 +89,8 @@ http { } location /api/getChart { + limit_req zone=kekkai burst=4; + proxy_pass http://chart_backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -79,6 +99,8 @@ http { } location /static/chart { + limit_req zone=kekkai burst=4; + proxy_pass http://chart_backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr;