DDoS Protection Basics: How to Mitigate Attacks on a Small VPS

DDoS Protection Basics: How to Mitigate Attacks on a Small VPS

DDoS protection basics for a small VPS start with a hard fact: a single small server cannot absorb a large flood on its own. Mitigation on a small VPS is about slowing the attack, filtering the traffic you can filter, and pushing the rest upstream to a provider or CDN that has the capacity you do not. This guide covers each layer in order, so you spend effort where it helps instead of tuning a firewall against a flood it cannot hold back.

First, name the attack type, because each one needs a different answer. Volumetric attacks flood bandwidth with huge traffic. Protocol attacks exhaust connection tables with half-open connections. Application attacks send requests that look normal but cost your server real work, such as expensive searches or login attempts. A firewall rule that helps against one type can be useless against another, and the logs tell you which type you face if you read them before you act.

DDoS Protection Basics: Know What Kind of Attack Is Hitting You

Check load, connections, and bandwidth together. Run ss -s for connection counts, htop for CPU, and your provider graph for bandwidth. A flood of SYN packets with few completed connections points at a protocol attack. A flood of complete HTTP requests from many addresses points at an application attack. A bandwidth graph that jumps tenfold with no matching request log points at a volumetric flood that may never reach your web server at all.

Check the source pattern too. Traffic from a few addresses is not a distributed attack, and it can be blocked directly. Traffic from thousands of addresses with no shared pattern needs upstream help. Traffic that mimics real browsers, with normal user agents and full page loads, is the hardest case, and it is where rate limits and caching matter more than blocklists.

Nginx Rate Limiting DDoS Requests at the App Layer

For application attacks, Nginx rate limiting is the first useful layer. It caps how many requests one address can make in a window, which turns a flood from one bot into a trickle your server can ignore. A basic setup in the http block looks like this, and the same zone idea is covered for login pages in our guide to setting up a firewall with UFW on Ubuntu Server 24.04 companion steps:

limit_req_zone $binary_remote_addr zone=main:10m rate=10r/s;

Then apply it in a location block with limit_req zone=main burst=20 nodelay;. The burst value lets a real visitor load a page with its assets without tripping the limit, while a bot hammering the same endpoint hits the cap fast. Tune the rate from your own logs, not from a blog default: a site with heavy API use needs a higher rate than a brochure site. Burst, delay, and per-endpoint zones each deserve their own tuning pass once the base zone works.

Rate limiting also protects login and search endpoints specifically. Apply a stricter zone to /wp-login.php, /login, and search URLs, because those are the endpoints attackers abuse for credential stuffing and for expensive queries. A login that allows ten attempts per minute per address still serves real users, who rarely need more, while it makes a brute force campaign crawl.

Syn Flood Firewall Rules and Connection Limits

For protocol attacks, the kernel and firewall do the work. Enable SYN cookies, which let the server handle half-open connections without storing state for each one:

sudo sysctl -w net.ipv4.tcp_syncookies=1

Make it permanent by adding net.ipv4.tcp_syncookies=1 to /etc/sysctl.conf. Then limit new connections per address with a firewall rule. With iptables, a rule using the connlimit match caps concurrent connections from one address, and a rule using the recent match caps new connections per minute. With UFW as the front end, the same ideas need raw iptables rules added through /etc/ufw/before.rules, because UFW itself has no per-address connection limit option. Our UFW configuration guide covers the base rules these additions build on, and the firewall comparison helps you pick the tool that fits your comfort level.

Keep connection timeouts short for half-open states. A server that holds a half-open connection for minutes gives an attacker a cheap way to fill its table, while a short timeout frees the slot fast. These kernel settings help, but they do not fix a flood that fills your network link: once the pipe is full, no server-side rule sees the traffic at all.

Cloudflare DDoS Mitigation and Provider Controls

When the flood exceeds your link, the answer sits upstream. A CDN or DDoS protection service absorbs traffic at its edge and forwards only clean requests to your server. Cloudflare offers this on its free plan for basic protection, with stricter modes under attack: the “Under Attack Mode” adds a browser check that blocks simple bots while letting real browsers through, at the cost of a short delay for first-time visitors. Check official pricing for paid tiers before you rely on a feature, because limits and features differ by plan.

Your VPS provider also has controls: some offer network-level filtering, null-routing, or a scrubbing service on request. Contact support during an attack and ask what they can filter upstream, because a provider-side block stops the flood before it reaches your link. Also hide your origin IP: if attackers know the real server address, they can bypass the CDN and hit the origin directly. Keep DNS pointed at the CDN, firewall the origin to accept only CDN addresses where possible, and never publish the origin IP in a public record.

Caching and Static Fallbacks That Shrink the Target

A cached page costs almost nothing to serve, so an application attack against a cached page hurts far less than one against a dynamic page. Put Nginx FastCGI cache or a CDN cache in front of dynamic pages, cache static assets with long headers, and serve a static fallback page during an attack if the app itself is the target. A site that shows a simple cached page during a flood stays useful, while a site that runs a database query per request falls over fast. Our FastCGI cache guide shows the Nginx side of this setup.

Also reduce expensive endpoints during an attack. Disable site search if it is the target, add a captcha or a proof-of-work check to forms under abuse, and turn off XML-RPC or other endpoints you do not use. Each endpoint you close is one less place an attacker can spend your CPU. Our guide to disabling XML-RPC covers one such endpoint for WordPress sites.

What to Do During an Attack, Step by Step

During an attack, work in this order. First, confirm it is an attack and name the type from logs and graphs. Second, apply the matching layer: rate limits for app floods, firewall and kernel rules for protocol floods, upstream help for volumetric floods. Third, enable the CDN under-attack mode if you use one. Fourth, tell your provider and ask for upstream filtering. Fifth, watch the graphs, not just the site: a site that loads for you may still be dropping other visitors, and a graph that stays flat after a change means the change worked.

After the attack, keep the lessons. Note the attack type, the source pattern, the rule that helped, and the time to recover. Add the working rules to your permanent config, set up monitoring that alerts on connection spikes and bandwidth jumps, and test the setup with a load test from your own machines, not with a real attack tool against a production site. A small VPS will never out-muscle a large botnet, but a layered setup with upstream help can ride out the attacks a small site normally faces, and that is the realistic goal.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.