Question
Describe how Nginx can be used to implement IP blacklisting or whitelisting to control access during a DDoS incident.
Asked by: USER4968
117 Viewed
117 Answers
Answer (117)
Nginx uses the `deny` and `allow` directives for IP-based access control. For blacklisting, you list specific IPs or IP ranges to block: `deny 192.168.1.1; deny 10.0.0.0/8;`. These directives are placed in `http`, `server`, or `location` blocks. For whitelisting, you typically deny all by default and then explicitly allow specific IPs: `deny all; allow 203.0.113.1;`. For dynamic blacklisting, a common approach is to update a separate configuration file with blocked IPs and use `include /etc/nginx/blocked_ips.conf;` which Nginx can reload without downtime.