From 52e0c85a08b9a29d2ac24b0c9040a86c7c30ba23 Mon Sep 17 00:00:00 2001 From: whirigoyen Date: Tue, 31 Aug 2021 18:22:35 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20section=20Limiter=20le=20taux?= =?UTF-8?q?=20de=20requ=C3=AAtes=20par=20IP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HowtoNginx.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/HowtoNginx.md b/HowtoNginx.md index 39001ecf..773845b4 100644 --- a/HowtoNginx.md +++ b/HowtoNginx.md @@ -572,6 +572,27 @@ EOT # systemctl restart nginx ~~~ +### Limiter le taux de requêtes par IP + +On peut définir un « taux » maximum de connexions par IP, ainsi qu'une queue pour les requêtes qui dépassent cette limite. + +Doc : [https://www.nginx.com/blog/rate-limiting-nginx/](https://www.nginx.com/blog/rate-limiting-nginx/) + +Ajouter dans `/etc/nginx/conf.d/zzz-evolinux-custom.conf` : + +~~~ +# Define the parameters for rate limitation (10Mo cache memory, max 1 request/100ms for an IP) +limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s; +~~~ + +Ajouter dans le bloc `server` des vhosts concernés : + +~~~ +# Define the rate limit, queue up the resquests to 20 if the rate limit is exceeded, nodelay answers immediatement the requests in the rate limit +limit_req zone=mylimit burst=20 nodelay; +~~~ + + ## SSL ~~~