Survive DDoS Attacks: Server Defenses Every E‑Commerce Site Needs
Protect your e‑commerce VPS from DDoS with hardened kernel settings, rate‑limit rules, Fail2Ban, and web‑server throttling—no CDN needed.
5 min read
Running an e‑commerce site means your business depends on a web server that stays online even when attackers try to overwhelm it. Distributed Denial‑of‑Service (DDoS) attacks are common, and while no single technique guarantees 100 % protection, a layered, server‑level defense can significantly reduce their impact. This guide shows practical steps you can apply on a typical Linux VPS or dedicated server—whether you use Debian/Ubuntu (apt) or AlmaLinux/Rocky Linux 8 (dnf). The focus is on configurations you control directly, without relying on external CDNs or third‑party mitigation services.
1. Harden the Network Stack
The kernel processes every incoming packet before any application logic runs. Tweaking sysctl parameters helps the server handle sudden traffic spikes and drop malformed packets that attackers often use.
# Edit /etc/sysctl.conf with the same lines
sudo vi /etc/sysctl.conf
sudo sysctl -p
What each setting does:
tcp_syncookies – protects against SYN floods by generating cookies instead of allocating a full connection slot.
tcp_max_syn_backlog – expands the queue for half‑open connections.
tcp_tw_reuse – allows TIME_WAIT sockets to be reused, freeing resources faster.
somaxconn – raises the limit for pending connections that a listening socket can accept.
2. Deploy Rate Limiting with iptables or nftables
Blocking traffic purely by IP is ineffective against large botnets, but limiting the rate of new connections per source can stop many volumetric attacks.
Using iptables (both families)
# Limit new TCP connections to 10 per minute per IP on port 80/443
sudo iptables -A INPUT -p tcp --dport 80 -m conntrack --ctstate NEW \
-m recent --set --name HTTP
sudo iptables -A INPUT -p tcp --dport 80 -m conntrack --ctstate NEW \
-m recent --update --seconds 60 --hitcount 10 --rttl --name HTTP -j DROP
sudo iptables -A INPUT -p tcp --dport 443 -m conntrack --ctstate NEW \
-m recent --set --name HTTPS
sudo iptables -A INPUT -p tcp --dport 443 -m conntrack --ctstate NEW \
-m recent --update --seconds 60 --hitcount 10 --rttl --name HTTPS -j DROP
# Save rules
# Debian/Ubuntu
sudo netfilter-persistent save
# AlmaLinux/Rocky
sudo service iptables save
Using nftables (modern alternative)
# Create a table and chain for HTTP/HTTPS
sudo nft add table inet filter
sudo nft add chain inet filter input { type filter hook input priority 0; }
# Rate limit rule (10 connections per minute per IP)
sudo nft add rule inet filter input ip protocol tcp ip dport {80,443} ct state new \
limit rate 10/minute burst 20 reject
# Persist the configuration
sudo sh -c 'nft list ruleset > /etc/nftables.conf'
These rules allow legitimate users to connect while silently dropping bursts that exceed normal browsing patterns.
3. Enable Application‑Level Throttling
Web servers and application frameworks often provide modules to limit request rates per client. Configuring them adds another barrier before traffic reaches your code.
The limit_req_zone directive creates a shared memory zone that tracks requests per IP. The example caps each client at five requests per second, with a short burst allowance.
The http-get-dos filter (included with Fail2Ban) triggers when a single IP makes more than 100 requests within a minute, temporarily blocking it for ten minutes.
5. Optional Advanced Step: SYN‑Proxy and Connection Queueing
For sites that experience large‑scale SYN floods, enabling SYN‑proxy offloads the handshake to the kernel, discarding bogus SYN packets before they consume resources.
These settings increase the backlog and allow the kernel to handle more half‑open connections without allocating full socket structures.
6. Monitor and Respond in Real Time
Even with strong defenses, visibility is essential. Set up lightweight monitoring that alerts you when traffic patterns deviate.
netstat / ss – watch for unusually high counts of SYN_RECV sockets.
vnStat or iftop – track bandwidth spikes.
Prometheus + Grafana – collect node_exporter metrics and create alerts for CPU, memory, and network thresholds.
Example command to list SYN‑RECV sockets:
ss -s | grep SYN‑RECV
If you notice a sustained rise, consider temporarily increasing tcp_max_syn_backlog or scaling out to additional servers behind a load balancer.
Conclusion
Protecting an e‑commerce platform from DDoS attacks starts with a hardened network stack, layered rate limiting, and application‑level throttling. Tools such as iptables, nftables, Fail2Ban, and web‑server modules give you concrete controls that work directly on your VPS or dedicated server, regardless of whether you run Debian/Ubuntu or AlmaLinux/Rocky. Combined with real‑time monitoring, these measures help you absorb most volumetric attacks, keep checkout pages responsive, and maintain customer trust.