-
Rate limiting
- Protects your server from DDoS, abusive clients, and aggressive scrapers by limiting request rates per client.
- Choose limits that match your traffic patterns to avoid blocking legitimate users while mitigating abuse.
-
Caching
- Reduces backend load by serving repeated requests from cache.
- Use proper
Cache-Controlheaders and design cache keys carefully (consider query strings, cookies, and vary rules) to maintain correctness and freshness.
-
Compression
- Speeds transfers for text-based assets (HTML, CSS, JS, JSON). Most images (JPEG, PNG, WebP) are already compressed and gain little from gzip.
- Significant improvements are common for compressible assets (for example, asset load times improving from ~5s to ~1s in many setups). Balance CPU overhead with throughput in high-traffic environments.
-
Keepalive connections
- Avoids establishing a new TCP connection per request, lowering latency and CPU/network overhead on client and server.
- Tune timeouts and max keepalive requests to match your traffic profile.

-
Worker configuration
- NGINX worker processes and connections determine how well the server uses CPU cores and handles concurrency. Generally set
worker_processesto the number of CPU cores and adjustworker_connectionsto suit concurrent clients and available file descriptors.
- NGINX worker processes and connections determine how well the server uses CPU cores and handles concurrency. Generally set
-
Logging and log format
- Enable access and error logs for troubleshooting and forensic analysis. Customize the access log format to include fields you need (client IP, request, response code, upstream time, request_id, etc.) to support debugging and analytics.
-
Monitoring and metrics
- Integrate an observability solution to collect metrics and alerts (uptime, error rates, latency, resource usage). Monitor NGINX metrics (connections, request rate, upstream times) and system metrics (CPU, memory, network).
- Commercial options:
- Open-source stack:
- Prometheus + Grafana — flexible and cost-effective, but requires more setup.
For production deployments, combine observability (metrics + logs) with alerting so you can detect regressions (e.g., increased latency or error spikes) before customers complain. Consider adding request tracing if you operate many upstream services.
- Enable compression and keepalive by default for most web applications; these give large wins for text assets and reduce latency.
- Configure rate limiting to protect against abuse while aligning thresholds with legitimate usage. Test with realistic traffic patterns.
- Tune worker counts and
worker_connectionsto match your hardware and expected concurrency. - Always keep access/error logs enabled and choose a log format that supports your troubleshooting and analytics needs.
- Add a monitoring and alerting solution so you’re notified when service health degrades.
Be cautious with aggressive rate limits and overly broad gzip rules. Too-strict rate limits can block real users; compression increases CPU usage—profile your server under load before enabling aggressive settings.