Nginx Timeout: Configuration

Resolve timeout problems with Nginx.

Nginx often acts as a reverse proxy in front of PHP-FPM, Node.js or other backends. If the backend is too slow, Nginx returns a 504 Gateway Timeout error. Here's how to configure correctly.

Symptoms

  • "504 Gateway Timeout" error
  • Long requests that fail
  • Uploads that timeout
  • Prematurely closed connections

Common Causes

  • Slow backend: PHP-FPM or the application takes too long to respond.
  • Timeout too short: Nginx directives configured with values too low.
  • Backend connection: Backend socket or port not responding.

Diagnostic Steps

  1. Check Nginx logs (error.log)
  2. Test direct backend access (curl localhost:9000)
  3. Examine current timeout values
  4. Verify PHP-FPM is running (systemctl status php-fpm)

Automate with MoniTao

MoniTao detects timeouts:

  • HTTP monitoring with configurable timeout
  • Alerts on 504 errors
  • Response time history

Best Practices

  • Configure proxy_read_timeout according to your needs
  • Align Nginx timeouts with PHP max_execution_time
  • Use longer values for uploads
  • Put long operations in background (queue)

FAQ

What timeout directives in Nginx?

proxy_connect_timeout, proxy_send_timeout, proxy_read_timeout, fastcgi_read_timeout.

What default value?

60 seconds by default. Adjust according to your longest operations.

How to increase for uploads?

Use client_max_body_size and increase timeouts in the concerned location.

Can MoniTao test with long timeouts?

Yes, configure the timeout in monitor settings.

Ready to Sleep Soundly?

Start free, no credit card required.