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 ~~~