Server errors require systematic debugging. This guide teaches the methodology to diagnose any Nginx or Apache error quickly and confidently.
Step 1 — The Debugging Hierarchy
# Always check in this order:
1. Web server error log (nginx/apache)
2. Application error log (PHP, app)
3. System log (syslog, journalctl)
4. Service status (systemctl)
5. Configuration test (nginx -t)
Step 2 — Read Nginx Error Log
# Real-time error monitoring
sudo tail -f /var/log/nginx/error.log
# Filter by severity
sudo grep "\[error\]" /var/log/nginx/error.log | tail -20
sudo grep "\[crit\]" /var/log/nginx/error.log | tail -20
# Find errors for specific domain
sudo grep "yourdomain.com" /var/log/nginx/error.log | tail -20
Step 3 — Test with curl
# Test from server (bypasses Cloudflare)
curl -I http://localhost
curl -I https://yourdomain.com
curl -v https://yourdomain.com 2>&1 | head -50
# Test with specific Host header
curl -H "Host: yourdomain.com" http://YOUR_SERVER_IP/
# Test response time
curl -w "
%{time_total}s
" -o /dev/null -s https://yourdomain.com
Step 4 — Test Nginx Configuration
# Test config before applying
sudo nginx -t
# Reload without restart (no downtime)
sudo nginx -s reload
# Show effective configuration for domain
sudo nginx -T | grep -A 20 "server_name yourdomain"
Step 5 — Common Status Codes and Fixes
# 400 Bad Request — malformed request headers
# Check: client_max_body_size, large_client_header_buffers
# 403 Forbidden — permission or index issue
# Check: file permissions, index directive, directory listing
# 404 Not Found — wrong root or try_files
# Check: root path, try_files directive
# 413 Payload Too Large — upload too big
client_max_body_size 100M;
# 499 Client Closed — timeout
# Check: fastcgi_read_timeout, proxy_read_timeout
Step 6 — Enable Verbose Logging
# Increase Nginx log level temporarily
error_log /var/log/nginx/error.log debug;
# Remember to set back to: error_log /var/log/nginx/error.log warn;
Conclusion
Systematic debugging resolves any server error quickly. Our team provides expert server debugging and emergency support.
Comments