Scenario
An e-commerce platform uses Nginx as an API gateway middleware for routing, rate limiting, caching, etc. During a flash sale, users report slow API responses and timeouts.
Symptoms
- API latency spikes from 50ms to over 500ms
- Error rate jumps from 0.5% to 5%
- Nginx worker CPU usage consistently above 80%
- Memory usage abnormally high
Diagnosis
- Check access logs:
tail -f /var/log/nginx/access.logto observe response time distribution. - Check error logs:
tail -f /var/log/nginx/error.logfor connection timeouts, worker crashes. - Enable status module: Add to server block:
location /nginx_status { stub_status; }Access/nginx_statusfor active connections, requests, etc. - Load testing: Use
ab -n 10000 -c 100 http://localhost/nginx_statusto simulate concurrency. - Analyze configuration: Review
worker_processes,worker_connections,keepalive,proxy_buffersetc.
Tuning Commands
# Test configuration syntax
nginx -t
# Graceful reload
nginx -s reload
# Adjust worker processes (match CPU cores)
worker_processes auto;
# Or manual: number of CPU cores * 1-2
# Increase worker connections
events {
worker_connections 4096;
use epoll;
multi_accept on;
}
# Optimize buffers
proxy_buffers 8 16k;
proxy_buffer_size 16k;
proxy_busy_buffers_size 24k;
# Enable keepalive
gzip on;
gzip_min_length 1000;
upstream backend {
keepalive 32;
}
# Rate limiting
limit_conn_zone $binary_remote_addr zone=addr:10m;
limit_conn addr 10;
Risk Controls
- Backup config before changes:
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak - Always validate with
nginx -tbefore reload - Avoid changes during peak traffic
- Monitor at least 10 minutes after each adjustment
Rollback
cp /etc/nginx/nginx.conf.bak /etc/nginx/nginx.conf
nginx -s reload
Verify by checking error logs and response times.
Verification
- Measure response time:
curl -o /dev/null -s -w %{time_total}\n http://api.example.com/status - Observe active connections on Nginx status page
- Compare load test results before and after
- Confirm error rate returns to normal
When to Submit an OpsGlobal Ticket
- Performance still unsatisfactory after tuning
- Frequent worker crashes
- Upstream servers healthy but Nginx proxies abnormally
- Complex configuration with unclear bottlenecks
Use cases
Useful for teams handling Performance issues and needing a clear troubleshooting and delivery workflow.
Problem background
This article walks through a real-world scenario of performance degradation in an Nginx-based API gateway middleware, covering symptoms, diagnosis, tuning commands, risk controls, rollback, verification, and when to escalate to OpsGlobal.
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.