Scenario
An e-commerce platform uses Nginx as an API gateway. During a flash sale, traffic spikes cause response latency and timeouts.
Symptoms
- Clients observe high latency (>5s)
- Nginx error logs show 'upstream timed out'
- System load high but CPU not maxed
Diagnosis
- Check Nginx status:
curl http://localhost/nginx_status- look for high Active connections or Waiting queue. - Analyze access logs:
tail -f /var/log/nginx/access.logto identify slow requests. - Trace system calls:
strace -p <nginx_pid>reveals excessiveepoll_wait. - Verify upstream:
time curl -XGET http://upstream/healthto ensure backend is responsive.
Commands
Adjust Worker Processes
worker_processes auto;
Optimize Event Model
events {
worker_connections 10240;
use epoll;
multi_accept on;
}
Increase Proxy Timeouts
location /api {
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
Enable Cache (optional)
proxy_cache_path /tmp/cache levels=1:2 keys_zone=api_cache:10m max_size=1g inactive=60m;
Risk Controls
- Backup config:
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak - Validate with
nginx -tbefore reload - Monitor connections during reload: watch
nginx_status - Use canary testing: apply changes to a subset of upstream servers first
Rollback
If performance degrades or errors appear:
cp /etc/nginx/nginx.conf.bak /etc/nginx/nginx.conf
nginx -s reload
Verification
- Check latency:
tail -f /var/log/nginx/access.log | awk '{print $NF}'- should decrease - Load test:
ab -n 10000 -c 100 http://localhost/api/test - Confirm no timeouts in error.log
When to Submit an OpsGlobal Ticket
- Performance doesn't improve after tuning
- Upstream is healthy but Nginx still times out
- Need deeper analysis (e.g., kernel tuning, custom modules)
- Capacity planning or architecture review required
Use cases
Useful for teams handling Performance issues and needing a clear troubleshooting and delivery workflow.
Problem background
A practical guide to diagnosing and resolving Nginx API gateway performance bottlenecks, including configuration tuning, risk controls, and rollback procedures for SRE teams.
Troubleshooting steps
Confirm impact and recent changes, collect logs, configuration and metrics, then apply fixes from low to high risk.
Command examples
Replace sample resource names with real values and store passwords, tokens and keys in environment variables.
Risks
Before production changes, confirm backups, access boundaries, change windows and rollback paths.
Rollback plan
Keep original configuration and release versions; roll back config, images or database changes if metrics degrade.
Deliverables
Root-cause notes, key commands, remediation steps, verification results and follow-up recommendations.
Need help with a similar technical issue?
If your servers, Kubernetes, Docker, CI/CD, databases or monitoring systems have similar issues, submit logs and config files for remote diagnosis.