🛡️
Security

L7 DDoS: Protecting Your Site from Bot Requests

29.11.2026
← All articles

How an L7 attack differs from normal traffic

Network and transport-level DDoS floods a server with packets and is mostly handled by the data centre. An L7 (application layer) attack instead sends complete HTTP requests that look like a normal browser. Each one is harmless on its own, but thousands of them keep every PHP worker and the database busy. It needs little bandwidth: a few hundred IPs sending several requests per second can bring down a dynamic site, especially if they target uncacheable pages such as search, cart, filters or URLs with random parameters.

Recognising the attack in logs

Slow pages, 502 or 504 errors and a load spike can also come from a real marketing campaign, so check the access log. Attack traffic usually hits the same URLs at an unnatural rate with similar User-Agent strings:

awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20
awk '{print $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20
awk -F'"' '{print $6}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20
awk '{print $1}' /var/log/nginx/access.log | cut -d. -f1-3 | sort | uniq -c | sort -rn | head

When requests are spread evenly over hundreds of addresses, look for a shared trait: the same URL pattern, an outdated browser version in the User-Agent, a missing Referer or addresses from one network. A private school in Tashkent, for instance, went down during its admissions period because hundreds of IPs were hammering the /?s= search page with random words. A separate rate limit for search plus a few User-Agent blocks restored the site within minutes, and real parents noticed nothing.

The first barrier in Nginx

Nginx can reject a request cheaply before it reaches PHP:

# inside http { ... }
map $http_user_agent $bad_bot {
    default 0;
    ~*(python-requests|go-http-client|scrapy|httpclient) 1;
    "" 1;
}
limit_conn_zone $binary_remote_addr zone=perip_conn:10m;
limit_req_zone  $binary_remote_addr zone=search:10m rate=1r/s;

# inside server { ... }
if ($bad_bot) { return 403; }
limit_conn perip_conn 20;

location / {
    if ($arg_s) { return 418; }
    try_files $uri $uri/ /index.php?$args;
}
error_page 418 = @search;
location @search {
    limit_req zone=search burst=5 nodelay;
    try_files $uri /index.php?$args;
}

Be careful about adding curl to the list, since monitoring services and your own integrations may use it. Always validate before reloading with nginx -t && systemctl reload nginx. If an attack clearly comes from one network, block it with deny 198.51.100.0/24; in Nginx or, for large lists, at the firewall so connections never reach Nginx:

iptables -I INPUT -s 198.51.100.0/24 -p tcp -m multiport --dports 80,443 -j DROP

Caching makes attacks expensive

When pages are served from cache, each request costs a fraction of a PHP render. A page-cache plugin on WordPress or Nginx fastcgi_cache on a VPS serves ready HTML to anonymous visitors, and even a cache of a few seconds means that out of hundreds of identical requests per second only one reaches PHP. Attackers try to bypass caching with random parameters, so strip unnecessary parameters from the cache key and put stricter limits on dynamic pages.

When you need a CDN and WAF

If the attack exceeds what the server can absorb, an external layer such as Cloudflare filters requests in its own network, challenges suspicious clients and forwards only those that pass. Hide your origin IP and allow direct connections only from the CDN's ranges, and enable Nginx real_ip so logs and limits see the real client address rather than CDN nodes.

During and after an attack

Save the access log, limit the heaviest pages first, add blocking rules step by step while checking that real users are unaffected, and relax temporary rules afterwards while keeping permanent limits. On shared hosting you cannot change server settings, so send support the times and addresses involved; sayt.uz hosting and VPS customers can do this through a ticket in the cabinet.

Related articles

📧 Email spoofing: someone is sending mail in your name, what to do 🔐 Security when granting permissions to AI agents 🎭 Deepfake fraud: the fake call from your CEO 💳 Verifying Click and Payme payment callbacks with signatures
🌐 Language
🇺🇿 O⁠'zbek 🇺🇿 Özbek (yangi) 🇺🇿 Ўзбек 🇷🇺 Русский 🇬🇧 English ✓