Originally published at keston.dev — server security hardening for business websites. KESTON hardens and ships business web stacks with USDT/USDC milestone settlement and full source handover.
Put a new domain on the internet and within 24 hours your access log fills with the same requests: /wp-login.php, /.env, /.git/config, /xmlrpc.php, /actuator/env, /phpmyadmin/index.php, /vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php. Nobody is targeting you. It is a scanner sweeping the IPv4 space, and it will keep sweeping whether or not you answer.
Most small business stacks survive this by luck rather than design — until one of those paths hits something that answers. The fix is not a WAF subscription or a security audit. It is a two-hour pass over four files, and it removes the entire class of "someone found a forgotten debug endpoint" incidents.
Here is the pass, in the order I do it.
1. Stop serving things that were never meant to be served
The number one real-world leak is not an exploit. It is a file that existed in the web root: .git/, .env, backup.sql, dump.zip, .DS_Store, an editor's *.swp.
# /etc/nginx/snippets/deny-dotfiles.conf location ~ /\.(?!well-known) { deny all; access_log off; log_not_found off; } # common backup / dump / config leftovers location ~* \.(env|sql|bak|old|orig|swp|log|ini|dist|tar|gz|zip)$ { deny all; access_log off; } Include that snippet in every server {} block. The .well-known exception matters — ACME challenges and some verification flows live there.
Then verify from the outside, not from the file:
for p in .git/config .env backup.sql wp-login.php actuator/env; do printf "%-16s %s\n" "$p" "$(curl -s -o /dev/null -w '%{http_code}' https://example.com/$p)" done You want 403 or 404 for all five. If .git/config returns 200, you have a full source disclosure — /.git/ can be reconstructed into a repository with git-dumper in under a minute.
2. Turn off the version banner
server_tokens off; Two seconds of work, and it stops advertising nginx/1.18.0 (Ubuntu) so a scanner can match you against a CVE list without probing. It is not security by obscurity in the pejorative sense — you are removing a free hint, and there is no downside.
3. Rate-limit the endpoints that cost you money
An unthrottled /api/login or /api/send-code is three problems at once: credential stuffing, SMS-bill blowout, and CPU exhaustion.
limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m; limit_req_zone $binary_remote_addr zone=api:10m rate=30r/s; server { location = /api/login { limit_req zone=login burst=5 nodelay; limit_req_status 429; proxy_pass http://127.0.0.1:3000; } location /api/ { limit_req zone=api burst=60 nodelay; proxy_pass http://127.0.0.1:3000; } } 5r/m with burst=5 means a human logging in normally never notices, while a script gets 429 after six attempts. Put the same rule on password reset, OTP send, and any endpoint that triggers an email or an SMS.
Then add a second layer at the application: per-account lockout and a per-phone-number daily OTP cap. Nginx rate limits are per IP, and attackers rotate IPs.
4. Cap the request body
The cheapest DoS is a 2 GB POST. The second cheapest is an upload endpoint that writes to disk without a size check.
client_max_body_size 8m; client_body_timeout 15s; client_header_timeout 15s; send_timeout 20s; Raise client_max_body_size only on the specific upload location that needs it.
5. Close the proxy/backend surface
A lot of "server" breaches are actually a backend bound to 0.0.0.0:
ss -lntp | grep -E '0\.0\.0\.0|\[::\]' Node on :3000, Redis on :6379, Postgres on :5432, Elasticsearch on :9200 — every one of those open to the world is a breach waiting for a scanner that speaks the protocol. Bind them to 127.0.0.1 and let Nginx proxy. Then firewall everything except 22, 80, 443:
ufw default deny incoming ufw allow 22/tcp ufw allow 80,443/tcp ufw enable ss is the check that matters. Firewall rules and application config drift apart, and the listening socket is the truth.
6. TLS settings that are still correct in 2026
ssl_protocols TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers off; ssl_session_cache shared:SSL:10m; ssl_session_timeout 1d; ssl_stapling on; ssl_stapling_verify on; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header X-Frame-Options "SAMEORIGIN" always; Two notes. prefer_server_ciphers off is correct for modern Nginx — with TLS 1.3 the client order is better. And HSTS with includeSubDomains will break any subdomain still on HTTP, permanently, for the max-age window; check your subdomains before you turn it on.
7. SSH: the 10-minute version
# /etc/ssh/sshd_config PermitRootLogin no PasswordAuthentication no MaxAuthTries 3 Keep your current session open while you test a new one in a second terminal. If you lock yourself out with no console access, you will have a bad afternoon.
8. Make the logs tell you when something changes
You cannot watch dashboards. Set three alerts and forget them:
- 404/403 spike — a scanner found a new path and is hammering it
- 5xx rate above baseline — often the first symptom of resource exhaustion
- successful login from a new country for admin accounts
A one-line cron that mails you the top 20 offending IPs daily is enough:
awk '{print $1}' /var/log/nginx/access.log \ | sort | uniq -c | sort -rn | head -20 \ | mail -s "top IPs $(date +%F)" ops@example.com 9. Backups you have actually restored
An untested backup is a rumour. The pass is not complete until you have restored one into a scratch directory and loaded the site from it. Two things break restores in practice: the database dump excludes a table someone added later, and the uploads directory lives outside the backup path.
Test the restore quarterly. It takes 30 minutes and it is the difference between an incident and an outage.
The order that matters
If you only do three things, do these:
- Deny dotfiles and backup extensions (removes the most common real leak)
- Rate-limit login/OTP/email endpoints (removes credential stuffing and bill blowout)
- Bind backends to localhost and firewall the rest (removes the most common full compromise)
That is under an hour, and it covers the majority of what actually gets exploited on small business stacks. The rest — TLS hygiene, SSH, monitoring, tested restores — is another hour, and it is the difference between a site that is probably fine and one you can defend in a client security review.
Leon runs KESTON, an independent full-stack studio. The hardening checklist above is part of every delivery; see the server security hardening guide and pricing. Telegram · hello@keston.dev. Not affiliated with Keston Boilers (UK).
