Default Linux distribution packages ship Nginx configured for broad compatibility rather than resilience against malformed requests, slow-HTTP connection exhaustion, or protocol downgrades. Tightening a dozen directives in nginx.conf and virtual host includes significantly reduces attack surface without altering application logic.
1. Eliminating Protocol Downgrades & Server Banner Noise
Disable server version tokens and deprecate TLS 1.0/1.1 globally in /etc/nginx/nginx.conf:
http {
server_tokens off;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1d;
ssl_session_tickets off;
}
Turning off ssl_session_tickets preserves forward secrecy across long-lived processes when session ticket keys are not rotated automatically on a short schedule.
2. Bounding Client Header and Body Timeouts
Slowloris and stalled-POST tools hold Nginx worker file descriptors open by trickling one byte every few seconds. Tighten idle timeouts aggressively while leaving generous room for genuine file transfers on upload routes:
client_body_timeout 12s;
client_header_timeout 12s;
send_timeout 15s;
keepalive_timeout 30s;
client_max_body_size 16m;
3. Blocking Sensitive Files, Logs, and Private Storage Paths
Never rely solely on obscurity for .git, .env, SQLite databases, or JSONL submission logs stored inside a site directory. Explicitly deny access in Nginx before PHP or static fallbacks execute:
# Block dotfiles (except ACME well-known verification)
location ~ /\.(?!well-known) {
return 404;
}
# Block private application storage, cron scripts, and internal backups
location ~ ^/(storage|cron|site_src|verification)/ {
return 404;
}
4. Safe Proxy Buffering for Upstream Node or Go Backends
When proxying APIs over localhost or Tailscale, forward canonical client scheme headers and disable proxy server signature leaks:
location /api/ {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_hide_header X-Powered-By;
proxy_read_timeout 30s;
}
5. Verifying TLS Negotiation & Cipher Posture Live
After reloading Nginx, never rely solely on browser icons—verify supported protocol versions, HTTP/2 ALPN negotiation, and HSTS emission directly from OpenSSL and curl:
# Confirm TLS 1.0/1.1 fail cleanly while TLS 1.3 succeeds
openssl s_client -connect orangevpn.com.ph:443 -tls1_1 </dev/null 2>&1 | grep -E "Protocol|alert|error"
openssl s_client -connect orangevpn.com.ph:443 -tls1_3 </dev/null 2>&1 | grep -E "Protocol|Cipher"
# Confirm Server banner omits patch version and private folders return 404
curl -sI https://orangevpn.com.ph/storage/ | head -n 5
| Hardening Directive | Threat Mitigated | Compatibility Note |
|---|---|---|
server_tokens off; |
Targeted Nginx CVE version fingerprinting | Safe across all browsers and reverse proxies |
ssl_session_tickets off; |
Past TLS session key decryption if host restarts rarely | Keeps forward secrecy intact with TLS 1.2/1.3 |
limit_req burst=5 nodelay; |
Brute-force floods on auth and contact forms | Requires real_ip_header when behind Cloudflare |
Always run sudo nginx -t before issuing systemctl reload nginx so syntax errors never disrupt active virtual hosts.