How to configure ddos in ubuntu server with nginx

Blog By Aug 29, 2023 No Comments

Configuring DDoS Protection in Nginx on Ubuntu

To configure basic DDoS protection in Nginx on Ubuntu, follow these steps:

  1. Install Nginx:
sudo apt install nginx
  1. Limit the request rate:

Open the nginx.conf file:

sudo nano /etc/nginx/nginx.conf

Add the following lines in the http block:

limit_req_zone $binary_remote_addr zone=one:10m rate=30r/m;

This will limit requests to 30 per minute from each IP address.

  1. Limit the number of connections:

Add this to the http block:

limit_conn_zone $binary_remote_addr zone=addr:10m;

And add this to the server block:

limit_conn addr 10; 

This will limit each IP to 10 concurrent connections.

  1. Enable connection timeouts:

Add these lines to the http block:

client_body_timeout 10;  
client_header_timeout 10;
keepalive_timeout 5 5;
send_timeout 10;

This will close idle connections after 5 seconds.

  1. Denylist IP addresses:

To block specific IP addresses, add:


To the server block.

  1. Restart Nginx:
sudo systemctl restart nginx

These basic Nginx configuration options can help mitigate some DDoS attacks by limiting the rate of incoming requests, connections, and timeouts. However, for strong protection against large DDoS attacks, a dedicated DDoS protection service is recommended.



I'm Abhay Singh, an Architect with 9 Years of It experience. AWS Certified Solutions Architect.

No Comments

Leave a comment

Your email address will not be published. Required fields are marked *