troubleshooting

Fix Nextcloud 504 Gateway Timeout: Nginx and PHP-FPM

Trace a Nextcloud 504 to Nginx or PHP-FPM, check for busy workers or slow PHP requests, and find where to adjust the timeout safely.

Illustrated title card for the guide: Fix Nextcloud 504 Gateway Timeout: Nginx and PHP-FPM

A Nextcloud 504 means a gateway did not get a timely response from an upstream server it needed to complete the request. Check the Nginx error log for the failed request. If Nginx timed out reading from PHP-FPM, check for busy workers or slow PHP requests before raising fastcgi_read_timeout for an operation that needs longer. HTTP status 504 · Nextcloud server tuning

Find the upstream that timed out

Note the time and the operation that failed, then look for the matching request in the Nginx error log. Use the destination configured by error_log. If it points to /var/log/nginx/error.log, check it with this command. Nginx error log directive · Nextcloud Nginx guide

tail /var/log/nginx/error.log
What the log or configuration showsWhat to check
Nginx could not connect to the FastCGI upstreamMatch the server in upstream php-handler to listen in the PHP-FPM pool. For a Unix socket, use the same path with unix: prepended on the Nginx side. Nextcloud PHP handler setup
Nginx timed out reading the response header from the FastCGI upstreamCheck the PHP-FPM pool’s slow log and worker capacity before changing fastcgi_read_timeout. Nginx FastCGI timeouts · Nextcloud server tuning
A front-end Nginx using proxy_pass timed out reading from the Nextcloud web serverCheck that front end’s proxy_read_timeout. Nginx HTTP proxy read timeout

Check the PHP-FPM pool

Look for a slow request. In the PHP-FPM pool that serves Nextcloud, add or update these two directives from the Nextcloud tuning guide. Check the slow log for the PHP backtrace that FPM records when a request exceeds this example’s five-second threshold. Nextcloud server tuning · PHP-FPM configuration

slowlog = /var/log/php-fpm-slow.log
request_slowlog_timeout = 5s

Reload the PHP-FPM service after editing the pool. On Debian or Ubuntu with the PHP 8.3 service, use the command below. Match the service name to the version serving Nextcloud. Nextcloud server tuning

sudo systemctl reload php8.3-fpm

Check for a queue. If you already have a restricted PHP-FPM status page, check listen queue during the slowdown. It counts requests waiting for a free worker. max children reached tells you whether the pool has hit its worker limit since it started. PHP-FPM status fields

If requests keep queuing, use Nextcloud’s sizing rule to see whether RAM allows a higher pm.max_children. Divide the RAM available to PHP by the average resident memory per worker and round down. Leave headroom for the OS, web server, database, and cache. Nextcloud worker sizing

Check for a worker termination. To see whether the pool is configured to kill workers mid-request, check request_terminate_timeout. This setting can make FPM kill a worker when a request runs past the configured limit. PHP-FPM configuration

For application errors at the same time, check nextcloud.log in the configured data directory if Nextcloud uses file logging and the default log path. Nextcloud logging

Adjust the FastCGI read timeout

When an expected long operation hits the FastCGI read timeout, edit or add fastcgi_read_timeout in the existing PHP location. In Nextcloud’s sample configuration, this block contains fastcgi_pass php-handler;. Nextcloud Nginx configuration

Nginx closes the FastCGI connection when PHP-FPM sends no data within this interval between reads. Replace the default 60s below with an interval that covers the expected gap. For example, a final MOVE request can hit the timeout even when the upload uses chunks. Nginx FastCGI read timeout · Nextcloud large-file uploads

fastcgi_read_timeout 60s;

Reload Nginx and retry

Check the configuration. Nginx command-line options

nginx -t

If the check succeeds, reload Nginx to apply the change. Nginx command-line options

nginx -s reload

Retry the operation that failed and confirm it completes. If you still get a 504, check the Nginx error log again. Nextcloud large-file uploads · Nextcloud Nginx configuration

Evidence and limits. The Nextcloud 35 Administration Manual, the Nginx and PHP-FPM manuals, and RFC 9110 were checked on November 26, 2026. The commands and settings were not run on a Nextcloud installation.

Sources

  1. RFC 9110: 504 Gateway Timeout rfc-editor.org
  2. Nextcloud 35 Administration Manual: Server tuning docs.nextcloud.com
  3. NGINX: error_log nginx.org
  4. Nextcloud 35 Administration Manual: NGINX configuration docs.nextcloud.com
  5. Nextcloud 35 Administration Manual: PHP handler configuration docs.nextcloud.com
  6. NGINX FastCGI module: fastcgi_next_upstream nginx.org
  7. NGINX HTTP proxy module: proxy_read_timeout nginx.org
  8. PHP Manual: FPM configuration php.net
  9. PHP Manual: FPM status page php.net
  10. Nextcloud 35 Administration Manual: Logging docs.nextcloud.com
  11. NGINX FastCGI module: fastcgi_read_timeout nginx.org
  12. Nextcloud 35 Administration Manual: Uploading big files docs.nextcloud.com
  13. NGINX: Command-line parameters nginx.org

Related