Rate limiting
If you have an application or site where there's a login or you want to ensure fair use between different clients, rate limiting can help to help protect your system from being overloaded.
By limiting the number of requests (done per IP with NGINX), we lower the peak resource usage of the system, as well as limit the effectiveness of attacks which are attempting to brute force your authentication system.
How to do it...
Follow these steps for rate limiting:
- Firstly, we need to define a shared memory space to use for tracking the IP addresses. This needs to be added in the main configuration file, outside the standard
server
block directive. Here's our code:
limit_req_zone $binary_remote_addr zone=basiclimit:10m rate=10r/s;
- Then, within the
server
block, you can set which location you wish to limit. Here's what ourserver
block directive looks like:
server { listen 80; server_name limit.nginxcookbook.com; access_log /var/log/nginx...