Error Codes Wiki

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

  1. 1Test configuration: sudo nginx -t (fix errors before reloading)
  2. 2Check error log: tail -f /var/log/nginx/error.log for specific error messages
  3. 3For 502: verify backend is running (systemctl status php-fpm or equivalent)
  4. 4Increase timeouts: proxy_read_timeout 300s; proxy_connect_timeout 60s; in the location block
  5. 5Fix SSL: ssl_certificate must include the full chain (server cert + intermediate certs)
  6. 6Reload configuration: sudo systemctl reload nginx (not restart, to avoid downtime)

Tags

nginx502configurationupstreamweb-server

Related Items

More in Web Server

Frequently 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.