Skip to content
STAGE33R

Guides · Incident response and recovery · 6 steps · reviewed

Web server under a DDoS attack: confirm it, absorb it and keep the site up

A traffic spike is not always an attack: a campaign or a crawler looks the same at first. The first job is to know what you are seeing. The second is to move the cost of the traffic away from your server.

  1. Confirm what kind of traffic it is

    Look at connections, top client addresses and the most requested paths. One path hit by many addresses is different from one address hitting everything.

    sudo ss -ant | awk '{print $1}' | sort | uniq -c
    awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -n 10
    awk '{print $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -n 10
  2. Put a CDN or protection service in front

    The most effective step. Point the domain at a service that absorbs and filters traffic, then make the origin accept traffic only from it, so the attacker cannot go around.

  3. Rate limit and cache at the web server

    Limit requests per address on expensive paths and serve static or cached pages without touching the application.

    limit_req_zone $binary_remote_addr zone=perip:10m rate=10r/s;
    limit_req zone=perip burst=20 nodelay;
  4. Block what is clearly abusive

    Block the worst sources at the firewall or the edge rather than in the application. Block by network ranges only when you are sure.

    sudo ufw deny from OFFENDING_IP
  5. Ask your provider for help early

    Volumetric attacks are filtered upstream. Open a ticket with the times and the target address.

  6. Review afterwards

    Keep the logs, note how long it lasted, and write down what to prepare: a CDN, capacity, rate limits and contacts.

Common mistakes

  • Assuming a spike is an attack and blocking real customers.
  • Leaving the origin address reachable, so the filter is bypassed.
  • Blocking whole countries or ranges in panic and cutting off users.

How to undo it

Remove the firewall rules and the rate limit lines once the traffic is normal, and reload nginx after testing the configuration.

Sources

Commands are for Debian and Ubuntu unless noted. Test on a copy first and keep a backup: you are responsible for changes on your own systems.