504 Gateway Timeout in nginx - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

504 Gateway Timeout in nginx
============================

### [\#Errors](https://rocketeersapp.com/knowledge/errors)

A 504 Gateway Timeout means nginx reached your application, but the application took too long to respond. Unlike a 502, the backend is alive, it is just slow.

 Published by [Mark van Eijk](https://rocketeersapp.com/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [About error 504](#content-about-error-504)
2. [Why do I see this error](#content-why-do-i-see-this-error)
3. [Solution](#content-solution)

[\#](#content-about-error-504 "Permalink")About error 504
---------------------------------------------------------

A `504 Gateway Timeout` is returned when nginx, acting as a reverse proxy, successfully connects to the upstream server but does not receive a complete response within the configured timeout window.

This is the key difference with a [502 Bad Gateway](/502-bad-gateway-nginx): with a 502 the backend gave a bad or no connection, with a 504 the connection was fine but the response never arrived in time.

[\#](#content-why-do-i-see-this-error "Permalink")Why do I see this error
-------------------------------------------------------------------------

The backend is taking longer than nginx is willing to wait. Common reasons:

- A slow database query or a missing index.
- A long running job (report generation, export, image processing) handled inside the request instead of a queue.
- A slow external API call the request depends on.
- PHP's own `max_execution_time` is lower than the work needs.

By default nginx waits 60 seconds (`proxy_read_timeout` for proxied apps, `fastcgi_read_timeout` for PHP-FPM) before giving up.

[\#](#content-solution "Permalink")Solution
-------------------------------------------

For a PHP-FPM application, raise the FastCGI read timeout in your `server` or `location` block:

 ```
location ~ \.php$ {
    fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    fastcgi_read_timeout 120s;
    include fastcgi_params;
}

```

For a proxied application (Node, Octane, a separate service), raise the proxy timeouts instead:

 ```
location / {
    proxy_pass http://127.0.0.1:8000;
    proxy_read_timeout 120s;
    proxy_send_timeout 120s;
}

```

PHP has its own limit too, so raise that as well or nginx will outwait a script that PHP already killed:

 ```
; php.ini
max_execution_time = 120

```

Reload after changing the configuration:

 ```
systemctl reload nginx
systemctl reload php8.3-fpm

```

Raising timeouts is a bandage, not a cure. The real fix is to make the request fast: add the missing database index, or move slow work (emails, exports, third-party calls) into a background queue so the request returns immediately. See [optimizing server performance](/optimize-server-performance) for more.

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#Errors](https://rocketeersapp.com/knowledge/errors)

- [Error in the HTTP2 framing layer](https://rocketeersapp.com/knowledge/error-in-the-http2-framing-layer)
- [413 Request Entity Too Large in nginx](https://rocketeersapp.com/knowledge/413-request-entity-too-large)
- [403 Forbidden in nginx](https://rocketeersapp.com/knowledge/403-forbidden-nginx)
- [ERR\_TOO\_MANY\_REDIRECTS (redirect loop)](https://rocketeersapp.com/knowledge/err-too-many-redirects)
- [CORS error: No Access-Control-Allow-Origin header](https://rocketeersapp.com/knowledge/cors-error-no-access-control-allow-origin)
- [curl (60) SSL certificate problem: unable to get local issuer certificate](https://rocketeersapp.com/knowledge/curl-60-ssl-certificate-problem-unable-to-get-local-issuer-certificate)

 [View all 11 articles →](https://rocketeersapp.com/knowledge/errors)
