Nginx Common Errors — Configuration Test Failed and Upstream Timeout
Errorweb server
Overview
Fix common Nginx errors including 'nginx: [emerg] configuration test failed', upstream timeout, 502 Bad Gateway, and SSL certificate configuration issues.
Key Details
- nginx -t tests configuration syntax before applying changes — always run before reload
- 502 Bad Gateway in Nginx means the upstream application server is not responding
- Nginx serves static files directly and proxies dynamic requests to backend applications
- Worker processes and connection limits affect how many concurrent requests Nginx can handle
- Log files: /var/log/nginx/error.log (errors) and /var/log/nginx/access.log (requests)
Common Causes
- Configuration syntax error: missing semicolon, mismatched braces, invalid directive
- Backend application (PHP-FPM, Node.js, Python) crashed or not running
- Upstream timeout: backend taking longer than proxy_read_timeout to respond
- SSL certificate file not found or certificate chain incomplete
- Permission denied on socket file or log directory
Steps
- 1Test configuration: sudo nginx -t (fix errors before reloading)
- 2Check error log: tail -f /var/log/nginx/error.log for specific error messages
- 3For 502: verify backend is running (systemctl status php-fpm or equivalent)
- 4Increase timeouts: proxy_read_timeout 300s; proxy_connect_timeout 60s; in the location block
- 5Fix SSL: ssl_certificate must include the full chain (server cert + intermediate certs)
- 6Reload configuration: sudo systemctl reload nginx (not restart, to avoid downtime)
Tags
nginx502configurationupstreamweb-server
Related Items
More in Web Server
linux-nginx-error-codesLinux Nginx Error Codes — 502, 504, 413 & Upstream Failures
Errorlinux-apache-error-codesLinux Apache Error Codes — AH01630, AH00558 & Module Errors
Warninglinux-nginx-502-bad-gatewayNginx 502 Bad Gateway — Upstream Server Connection and Proxy Errors
Errorlinux-nginx-504-gateway-timeoutNginx 504 Gateway Timeout — Slow Upstream Response and Timeout Configuration
Errorlinux-apache-mod-rewrite-errorsApache mod_rewrite Errors — URL Rewriting, .htaccess, and Redirect Loop Issues
Warninglinux-reverse-proxy-errorsReverse Proxy Errors — SSL Termination, Header Forwarding, and Backend Connection Issues
WarningFrequently Asked Questions
Use reload (systemctl reload nginx) to apply config changes without dropping active connections. Use restart only if reload fails or after a major update. Always run nginx -t before either.