Nginx Common Errors — Configuration Test Failed and Upstream Timeout
About Nginx Common Errors
Fix common Nginx errors including 'nginx: [emerg] configuration test failed', upstream timeout, 502 Bad Gateway, and SSL certificate configuration issues. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.
Here are the key things to understand: 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). Understanding these fundamentals will help you diagnose and resolve this issue more effectively.
The most common reasons this occurs include: 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. Identifying the root cause is the first step toward finding the right solution.
To resolve this, follow these recommended steps: Test configuration: sudo nginx -t (fix errors before reloading). Check error log: tail -f /var/log/nginx/error.log for specific error messages. For 502: verify backend is running (systemctl status php-fpm or equivalent). Increase timeouts: proxy_read_timeout 300s; proxy_connect_timeout 60s; in the location block. Fix SSL: ssl_certificate must include the full chain (server cert + intermediate certs). Reload configuration: sudo systemctl reload nginx (not restart, to avoid downtime). If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.
This article is part of our Linux Error Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.
Quick Answer
Should I use reload or restart?
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.
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)