Distributed denial-of-service (DDoS) attacks are not limited to banks and global platforms. Small WordPress sites, local e‑commerce stores and SaaS side‑projects can also be targeted by automated floods of traffic. The goal is simple: exhaust your bandwidth, CPU, RAM or connection limits so real visitors cannot load your site. A well‑designed mix of Cloudflare, smart rate limiting and sensible server tuning can reduce exposure without an enterprise security budget, but resilience depends on the attack and the capacity of each layer.
In this article, we’ll walk through a practical, layered DDoS protection strategy you can actually deploy. We’ll focus on three main pillars: using Cloudflare intelligently, designing effective rate limiting at the edge and on your origin, and hardening your server so it behaves predictably under stress. The examples cover shared hosting, VPS, dedicated servers and colocation. Which origin-side controls you can apply depends on your administrative access and hosting plan.
1. What DDoS Really Looks Like for Small and Medium Sites
1.1 Types of DDoS attacks you’re likely to see
DDoS is a broad term. In practice, small and medium websites usually face three main categories:
- Volumetric attacks: The attacker sends huge amounts of traffic (Gbps or more) to saturate your network connection or your provider’s upstream capacity.
- Protocol/transport attacks: SYN floods, UDP floods or malformed packets that consume resources in your TCP/IP stack, firewall or load balancer.
- Application‑layer attacks (Layer 7): Seemingly legitimate HTTP(S) requests to expensive endpoints (search, cart, login, API) designed to exhaust PHP, database and disk I/O.
Smaller sites can face a mix of volumetric traffic and targeted Layer 7 requests. A slow PHP endpoint may exhaust application capacity even when request volume is modest; the threshold depends on request cost and available resources.
If you want a conceptual refresher on attack types, you can also read our dedicated article explaining what DDoS is and how it works at the network and application layers.
1.2 Constraints specific to small and medium websites
A smaller site may have constraints such as:
- Limited bandwidth and connection limits on shared hosting or entry‑level VPS plans.
- Constrained CPU/RAM, especially if you run a CMS like WordPress, WooCommerce or a heavy PHP framework.
- Single-region hosting without globally distributed infrastructure.
- Minimal on‑call capacity: no 24/7 security team watching graphs.
Because of these constraints, your strategy cannot only be “add more hardware”. Instead, you need to filter and shape malicious traffic as far away from your origin as possible, then tune the origin to fail gracefully if something slips through.
2. A Layered DDoS Defense Model for Real‑World Sites
A layered DDoS protection design combines controls that complement each other:
- DNS and edge layer (Cloudflare): routes proxied web traffic through edge filtering before it reaches your server. Origin access restrictions are still needed to prevent direct bypass.
- Edge rate limiting: tracks request rates for selected endpoints and applies the configured mitigation. Basic plans count by IP; counting by a token-bearing header requires Advanced Rate Limiting and a suitable validated client identifier. Rate limiting is not authentication. Counter updates can lag, so this is not a strict cap on requests reaching the origin.
- Origin firewall and kernel: iptables/nftables/ufw, connection tracking and TCP tuning to improve handling of connection surges.
- Web server and application tuning: Nginx/Apache/LiteSpeed, PHP‑FPM and database settings that reduce the risk of a few heavy requests starving other work.
- Monitoring and incident playbook: metrics, logs and predefined actions so your response during an attack is calm and repeatable.
This layered approach is crucial. Cloudflare alone cannot protect a badly tuned origin from every Layer 7 pattern. Conversely, a perfectly tuned server can still be overwhelmed if you let an attacker throw millions of requests per second directly at it. You need both.
3. Using Cloudflare Effectively for DDoS Protection
Cloudflare is one of the most accessible DDoS mitigation tools for small and medium websites, because proxied web traffic can pass through it in front of existing hosting. Depending on your application, client-IP handling, integrations and cache rules may still need changes. But configuration matters a lot: an un‑tuned Cloudflare setup can still leak large amounts of malicious traffic to your origin.
For a more detailed configuration walkthrough, you can also check our dedicated guide on Cloudflare security settings, WAF, rate limiting and bot protection for small business sites. Below we’ll focus on the DDoS‑specific pieces.
3.1 Put your site fully behind Cloudflare
- Use proxied DNS (orange cloud): Make sure A/AAAA records for your web host are proxied, not DNS‑only. Otherwise Cloudflare cannot filter traffic.
- Do not leak your origin IP: Avoid publishing your server IP in additional DNS records, test subdomains, or email banners. Once the origin IP is known, attackers can bypass edge filtering if the origin still accepts their direct requests.
- Use Cloudflare-friendly DNS architecture: Our guide on choosing between Cloudflare DNS and hosting DNS explains how to structure nameservers and records safely.
3.2 Enable and tune Cloudflare WAF
The Web Application Firewall (WAF) helps filter malicious application requests and complements DDoS protection and rate limiting:
- Check your managed-rules entitlement: As of 4 November 2026, Cloudflare documents the Free Managed Ruleset on all plans, while the broader Cloudflare Managed Ruleset and OWASP Core Ruleset require Pro, Business or Enterprise. Enable the rules available to your zone and inspect false positives. The managed-rules documentation lists current availability.
- Review relevant CMS tags: Rules within a managed ruleset use tags such as wordpress for filtering and bulk configuration. Inspect the actual tags and rules for your WordPress or Magento application; do not assume each CMS has a separate ruleset switch. A tag override can also affect future rules, so scope exceptions carefully.
- Add custom rules for sensitive endpoints like
/wp-login.php,/xmlrpc.php,/cart,/checkout,/api/, using supported conditions such as URI, request method and user agent. Account for legitimate payment callbacks, authenticated users and integrations.
If you are primarily fighting WordPress bots and credential stuffing, our article on using Cloudflare WAF rules and rate limiting specifically to stop WordPress bots walks through real rule examples.
3.3 Cloudflare rate limiting for expensive endpoints
Start with endpoint-specific rate limits rather than imposing one global threshold. Focus on high‑cost actions:
- Login endpoints (
/wp-login.php,/user/login,/signin) - Search and filtering (
/search,?s=, filter parameters) - Checkout, cart and payment pages
- Public APIs (e.g.
/api/v1/)
The following per-IP thresholds are illustrative, not validated defaults. Compare them with legitimate peak traffic before enforcement, and confirm that your plan supports the required counting windows and actions:
- Login pages: an illustrative 5–10 requests per minute; select a counting period and block or browser-challenge action that your plan supports. A 60-second window is not available on every plan.
- Search endpoints: an illustrative 20–60 requests per minute; choose the supported mitigation and check its behavior. A timed block, a challenge and request throttling are different actions, not a generic queue that delays excess requests.
- APIs: 60–120 requests per minute per IP is only an illustrative range; set the threshold from your app’s legitimate client behavior, including automated clients.
When tuning these rules, watch Cloudflare analytics to spot false positives. Be especially careful with shared office IPs, VPNs and mobile carrier NATs where many legitimate users share one public IP.
3.4 Bot management and “challenge” modes
Granular Cloudflare bot scores, from 1 to 99, are available only to Enterprise customers who purchase Bot Management. Lower scores indicate likely automation; a score of 0 means the request was not evaluated. Grouped bot analytics on other eligible plans are not the same granular rule input. Use only the controls available on your plan and verify their effect on legitimate visitors and verified search-engine bots:
- Challenge high‑risk bots on browser pages rather than immediately blocking every suspicious request. Challenges may filter out unsophisticated tools without serving a full PHP page. Do not apply browser challenges indiscriminately to APIs, payment callbacks or other non-browser integrations.
- Use Under Attack selectively during a confirmed L7 attack: Cloudflare describes it as a last-resort measure that presents a Managed Challenge and can interrupt access and analytics. In the old dashboard, Security Level is fixed at Always protected with a separate Under Attack toggle; the new dashboard, API and Terraform use Security Level to manage Under Attack. If needed, scope it to affected browser pages with a configuration rule; keep API, webhook and payment callbacks out of browser challenges and remove the temporary mode after the attack.
- Consider country‑based rules when attack evidence supports them, but account for legitimate customers travelling abroad and integrations operating outside your sales region.
3.5 Protect the origin with Authenticated Origin Pulls and mTLS
Another important step is restricting public HTTP/HTTPS access to your origin so web requests must pass through Cloudflare:
- Restrict your server firewall to accept HTTP/HTTPS only from Cloudflare’s current IPv4 and IPv6 ranges, keeping administrative access on its separate approved path.
- Configure Authenticated Origin Pulls (AOP), Cloudflare’s origin-side mTLS: the origin must verify the presented client certificate against the expected AOP trust anchor. Global AOP uses a certificate shared across Cloudflare accounts, so it proves Cloudflare-network origin, not your particular account. For account-specific authentication, use zone-level or per-hostname AOP with your own dedicated certificate and matching origin trust. Generic mTLS with an unrelated or overly broad trusted CA does not establish that identity. Stage and test the setup before requiring the client certificate, then confirm direct requests without it fail. AOP needs Full or Full (strict) mode; it does not apply to Off/Flexible or Cloudflare Tunnel origins. It authenticates HTTPS, so close unused origin HTTP access or keep any required HTTP redirect endpoint separately restricted. See the AOP documentation.
We explained this model in detail in our article about protecting your origin with Cloudflare Authenticated Origin Pulls and mTLS. This helps reject direct web requests from attackers who discover your raw server IP, but origin-side filtering cannot prevent an upstream network link from being saturated.
4. Designing Smart Rate Limiting at Edge and Origin
Rate limiting is about fairness: preventing a single client (or small group of bots) from consuming your entire capacity. The trick is to apply limits as close to the attacker as possible while being gentle with legitimate bursty traffic.
4.1 Edge rate limiting vs origin rate limiting
You can (and usually should) combine:
- Edge rate limiting (Cloudflare): rejects matching excess HTTP requests before they reach the origin, reducing origin bandwidth use and connection pressure.
- Origin rate limiting (web server/firewall/application): provides a second line of defense if malicious traffic gets through, and gives you more granular control using internal signals.
4.2 Web server level rate limiting (Nginx, Apache, LiteSpeed)
Depending on the server and module, request limits can use an IP address, URL or validated application identity. Behind a reverse proxy, per-visitor limits require a client address supplied through a trusted proxy path; do not trust arbitrary client-supplied forwarding headers. Unvalidated cookies or headers are weak identities because attackers can change them.
For Apache, the inspected mod_evasive Apache 2.4 source uses r->useragent_ip for counting and blocking; mod_remoteip can supply the corrected request address. Older Apache 2.0 source uses r->connection->remote_ip, and distribution patches or forks may differ. Verify the installed implementation. For a direct Cloudflare-to-Apache path, configure RemoteIPHeader CF-Connecting-IP together with a maintained Cloudflare IPv4/IPv6 allowlist using RemoteIPTrustedProxy or RemoteIPTrustedProxyList. Without a proxy list, Apache can trust every source presenting that header. Restrict direct origin access and validate any extra proxies or Workers. If Pseudo IPv4 overwrites headers, disable that mode or use Add Header when the limiter needs the real IPv6 address. Compare Apache %a, %{c}a and module blocking logs in controlled tests; a corrected access log alone does not prove the counter uses it.
mod_evasive applies page and total request thresholds, not arbitrary URL-pattern-specific policies. Its counters are local to an Apache child process, with no hostname in the key; they do not form a quota shared across workers or servers, and virtual hosts within one process may share counts. Blocking returns 403 and further requests during the blocking period can extend it. Set different login/API policies in a suitable WAF, edge limiter or application. Apache mod_ratelimit limits each response’s transfer speed, not requests per visitor. More generally, common controls include:
- Connection limiting: cap simultaneous connections where appropriate; behind Cloudflare, transport-level source IPs identify proxies, so distinguish that scope from per-visitor HTTP limits.
- Request rate limiting: restrict how many requests an IP can make per second/minute.
- Burst handling: allow short spikes beyond the limit, but queue or drop if they continue.
Illustrative starting policies, not tested recommendations: adjust these values to measured capacity, legitimate bursts and users sharing an IP address.
- Maximum 10–20 concurrent connections per IP.
- Average 5–10 requests per second per IP on dynamic endpoints.
- More relaxed limits on static assets (CSS, JS, images) when cache hit rates and bandwidth measurements justify them; large files and cache misses can still be costly.
If you are comfortable at the firewall level, you can implement advanced patterns using nftables. Our cookbook on nftables‑based rate limiting and IPv6 rules for VPS servers shows how to combine connection caps and rate filters directly in the kernel.
4.3 Application-level rate limiting
Some attacks are best handled inside the application itself:
- Login attempts per username or email, not just per IP.
- API tokens or user IDs with their own per‑minute limits.
- Per‑session constraints so one compromised session cannot hammer your backend indefinitely.
For APIs and microservices, we have a separate article on rate limiting strategies with Nginx, Cloudflare and Redis. Many of those ideas can be adapted to smaller monolithic web apps as well.
4.4 Avoiding false positives when limiting rates
The biggest fear with rate limiting is blocking real customers. Some practical safeguards:
- Start in log/monitor mode if your platform supports it, so you can see who would be blocked before enforcing.
- Set limits by endpoint cost and legitimate traffic patterns, rather than assuming HTML pages always need higher limits than APIs. Account separately for asset requests and browser bursts.
- Use narrowly scoped exceptions for verified monitoring and payment traffic, limited to the endpoints and rates those integrations require rather than a blanket IP bypass.
- Implement separate rules for authenticated users, who may legitimately make more requests than anonymous visitors.
Monitor accidental blocking of verified search-engine crawlers as well as users. An accidental 403 can affect indexing and is not a crawl-rate control. Prolonged 429/5xx responses can slow crawling; do not grant a blanket bypass based only on a spoofable User-Agent string. See Google’s HTTP response guidance.
5. Server-Side Hardening and Tuning Against DDoS
Even with Cloudflare in front and good rate limiting, some abnormal traffic will still reach your origin. Your operating system, firewall and web stack should be tuned so they degrade gracefully instead of collapsing.
5.1 Kernel and network stack tuning
Linux has many sysctl parameters that influence how it handles large numbers of connections, SYN packets and buffer usage. Key areas to review:
- Connection tracking limits: ensure
net.netfilter.nf_conntrack_maxis set high enough for expected traffic but not so high that you run out of RAM during a flood. - SYN flood protection: review
net.ipv4.tcp_syncookiesagainst your running kernel. With kernel support, value 1 provides fallback when the SYN backlog overflows; it is not a substitute for capacity to handle legitimate traffic. - Backlog queues:
net.core.somaxconncaps the socket listen backlog, whilenet.ipv4.tcp_max_syn_backloglimits remembered SYN_RECV requests per listener. Compare current values, the application backlog and observed overflows before changing them. - Buffer sizes: adjust TCP buffer settings so long‑lived connections do not exhaust memory.
We have a detailed, real‑world walkthrough of these parameters in our article on Linux TCP tuning for high‑traffic WordPress and Laravel. Even if your site is smaller, use measured bottlenecks to decide which settings need changes; larger queues or buffers are not automatically beneficial.
5.2 Firewall configuration and basic DDoS protections
Your firewall is the last network gate before the web server. On a VPS or dedicated server, you should at minimum:
- Allow only required ports (80, 443 and any needed service ports), and restrict SSH to trusted administrative access paths. A non-standard SSH port is not a substitute for access controls.
- Use source-IP connection limits only where appropriate. A firewall behind a reverse proxy sees proxy connections, not individual visitors; low per-IP caps there can block many legitimate users together. Apply per-visitor request limits at a layer with trusted visitor identity.
- Drop malformed packets and obvious scans (e.g. invalid TCP flag combinations).
- Consider Fail2ban or similar tools for repeated authentication abuse, not as volumetric DDoS protection. For proxied HTTP traffic, ensure detection identifies the visitor through a trusted path and enforcement can target that visitor without banning a shared proxy address.
If you prefer a checklist, our guides on VPS security hardening (including Fail2ban and SSH best practices) and firewall configuration with ufw, firewalld and iptables give you step‑by‑step starting points.
5.3 Web server and PHP-FPM tuning
DDoS attackers love to exploit weak spots in your PHP and database stack. Some tuning basics:
- Limit PHP‑FPM workers (
pm.max_children) so they fit within a memory budget that also leaves room for the database, web server and operating system; otherwise, a spike can cause swapping or out-of-memory failures. - Set sane timeouts for fastcgi/proxy connections. You do not want stuck requests tying up resources for minutes.
- Enable caching for cacheable responses to reduce repeated backend work. Whether a cache hit bypasses PHP depends on the implementation. Exclude personalized and session-dependent responses, including cart, checkout and account pages.
- Graceful resource limits (max execution time, memory limits) to reduce resource exhaustion, while accounting for work outside the language runtime and checking that cancellation stops the relevant backend operation.
PHP‑FPM and OPcache tuning can reduce avoidable resource use, but cannot replace traffic filtering and capacity limits. For more hosting guides, browse the DCHost blog.
5.4 Logging and retention during attacks
Heavy DDoS traffic can also fill your disk via logs. Basic precautions:
- Set bounded log retention with appropriate size and rotation schedules; monitor disk usage and check the rotation job runs often enough for peak log growth.
- Consider sampling logs during extreme attacks if disk I/O becomes a bottleneck.
- Forward useful incident logs to external storage with access controls and a defined retention period. Avoid recording credentials, tokens or unnecessary personal data.
These measures reduce the risk of a “no space left on device” error during an attack; monitor free space and log growth as well.
6. Monitoring, Detection and an Incident Playbook
Protection is only half the story; you also need to notice attacks quickly and know what to do when they happen. Even small teams can set up lightweight monitoring that makes a big difference.
6.1 Metrics to watch
At minimum, keep an eye on:
- Requests per second at the edge (Cloudflare analytics) and at the origin (web server metrics).
- CPU, RAM and load average on the server.
- Network bandwidth in/out on the interface.
- HTTP status code distribution: spikes in 5xx or 429 often accompany attacks or misconfigured rate limits.
Tools like Netdata, Prometheus, Grafana or even simpler dashboards can help. We have a step‑by‑step guide on setting up VPS monitoring and alerts with Prometheus, Grafana and Uptime Kuma if you want a repeatable setup.
6.2 Basic DDoS incident playbook
During an attack, you do not want to improvise. A simple, written checklist already helps a lot:
- Assess whether it is a DDoS: compare Cloudflare and origin metrics with normal traffic patterns. Sudden RPS/bandwidth spikes warrant investigation but do not alone distinguish an attack from legitimate demand.
- Identify target endpoints: Is traffic hitting
/wp-login.php,/search,/api/, or random URLs? - Tighten Cloudflare rules: use available WAF rules and rate limits to target observed attack patterns. Restrict countries or IP ranges only where justified, and monitor legitimate traffic for false positives.
- Scale down non‑essential workloads on the same server (background jobs, heavy cron tasks) to free CPU and RAM.
- Adjust origin rate limits and timeouts to protect the database and PHP‑FPM.
- Log key details (time, IP ranges, user agents, URIs) for later analysis and longer‑term rule improvements.
After the incident, review what worked, what caused false positives and what can be automated for next time. Over a few iterations, your incident playbook becomes much smoother.
7. Hosting Architecture Choices for DDoS Resilience
No DDoS strategy is complete without a realistic look at your hosting architecture and capacity. You do not need a giant cluster for every project, but some patterns significantly improve resilience:
- Right‑sized VPS or dedicated server: enough CPU/RAM to handle your normal peaks with margin can help absorb additional load, though even a low-volume attack on an expensive endpoint may exhaust that margin.
- Separation of concerns: for higher‑traffic sites, consider splitting web and database servers or at least isolating background workers.
- DDoS-protected CDN/reverse proxy in front of your origin (e.g. Cloudflare) can mitigate attacks on traffic routed through it. DNS hosting alone does not shield the origin; direct attacks on the origin connection require upstream protection.
- Backup and disaster recovery: regular backups, tested restores and clear RPO/RTO targets so even in the worst case, you can rebuild.
When comparing shared hosting, VPS, dedicated servers and colocation, verify the chosen plan’s bandwidth and resource limits, upstream DDoS mitigation scope and incident escalation process. Establish who is responsible for Cloudflare DNS/proxy configuration and server‑side tuning, and whether the plan grants the access those changes require.
If you already host with us and want to harden an existing site against DDoS, a practical sequence is:
- Enable Cloudflare in front of your domain and proxy all public web records.
- Apply our Cloudflare WAF and rate limiting recommendations from the articles linked above.
- Implement relevant kernel, firewall and web server tuning based on our Linux TCP and firewall guides where you have administrative access. On managed or shared hosting, establish which changes the provider permits or handles.
- Set up basic monitoring and an incident checklist so you are not surprised by the next traffic spike.
You do not have to do everything at once. Edge protection, targeted rate limits and workload-appropriate server tuning can reduce attack impact, but none guarantees availability. Prioritize the bottlenecks shown by your monitoring and review legitimate-user access after each change.





