504 Gateway Time-out: Find the Layer That Timed Out

A 504 Gateway Time-out almost never means your internet connection is broken. It means a server in the middle (a CDN, load balancer or nginx) waited for the server behind it, and that server didn’t answer in time. Visitors can usually check whether it’s on their end in about a minute. Site owners need to find which layer gave up first, and this guide walks through each layer with its default timeout, the error it shows and the setting that changes it.

Timeout values, plan limits and version numbers were checked against vendor documentation in November 2026.

In short

  • A 504 comes from whichever middle layer stops waiting first, and that layer is rarely your browser or router.
  • If a 504 always arrives after about 30, 60 or 120 seconds, a specific layer’s default timeout is cutting it off.
  • A Cloudflare timeout shows up as error 524. A plain “504 Gateway Time-out” page with no Cloudflare branding comes from your host or origin.
  • Set timeouts so each inner layer is shorter than the one outside it: PHP, then nginx, then the load balancer, then the CDN.
  • Raising a timeout is the right fix for imports and backups. For normal page loads, it hides a slow query or a slow API call.

Fact-checked

We checked these key facts against the sources named, on November 23, 2026:

  • Many older guides still say 100 seconds, but the current docs say 120 (source: developers.cloudflare.com)
  • If an operation over 60 seconds always fails, that default is the cause (source: plesk.com)
  • If nginx’s limit is 60 seconds, nginx gives up first and returns the 504 (source: linuxize.com)
  • WordPress 7.0 “Armstrong”, released May 20, 2026, raised the minimum PHP version from 7.2.24 to 7.4 (source: make.wordpress.org)
  • A 504 that passes through Cloudflare without Cloudflare branding was produced by your host, load balancer or web server (source: developers.cloudflare.com)

What “504 Gateway Time-out” means

RFC 9110, the IETF’s current HTTP standard (it replaced RFC 7231), defines status 504 in section 15.6.5. It means a server acting as a gateway or proxy did not get a timely response from an upstream server it needed to complete the request. MDN Web Docs uses the same definition.

The important word is gateway. A typical request passes through several layers, and any of them can act as the gateway that runs out of patience:

Browser
  → CDN (Cloudflare, Amazon CloudFront)
    → Load balancer (AWS Application Load Balancer)
      → Web server (nginx or Apache)
        → PHP-FPM / Node.js app (WordPress, Next.js)
          → MySQL/MariaDB database or an external API

When the database takes 90 seconds to run a query, PHP waits for it, and nginx waits for PHP. If nginx’s limit is 60 seconds, nginx gives up first and returns the 504. The visitor sees the error, but the slow part is two layers deeper.

Common versions of the message

Each layer words the error differently, and the wording tells you who produced it:

  • “504 Gateway Time-out” on a plain white page with “nginx” underneath: the nginx default error page.
  • “Gateway Timeout. The gateway did not receive a timely response from the upstream server or application.”: Apache with mod_proxy.
  • “504 Gateway Timeout ERROR. The request could not be satisfied” with “Generated by cloudfront (CloudFront)”: Amazon CloudFront.
  • “504: GATEWAY_TIMEOUT” with code FUNCTION_INVOCATION_TIMEOUT: a Vercel function ran past its maximum duration.
  • “Gateway Timeout (504)” or “HTTP Error 504”: generic wording from browsers, apps and some hosts.
  • HTTP_STATUS_GATEWAY_TIMEOUT: the Windows WinHTTP constant. It shows up in Windows Update as error 0x80244023, where Microsoft’s update servers or a corporate proxy timed out.

Is a 504 your fault? A 60-second check for visitors

Almost never. A 504 is a server-side status code, so the problem sits between the website’s servers, not between you and the internet. The main exception is a VPN, corporate proxy or security tool that itself acts as a gateway.

If you’re a visitor

This is the answer to “everyone else seems to load it fine, is it me?” and “Reddit is showing 504 Gateway Timeout, is it just me?”:

  1. Wait 30 to 60 seconds and reload. Short overloads often clear by themselves.
  2. Open the same page on another device or on mobile data instead of Wi-Fi.
  3. Turn off your VPN, proxy or browser privacy extension and try again.
  4. Check the site’s official status page, or a status page for its platform (Cloudflare Status, AWS Health Dashboard, Shopify Status, Vercel Status). An outage tracker such as Downdetector shows whether other people are reporting problems.
  5. If it works everywhere except your network, restart the router or try a public DNS resolver. This rarely helps, because a 504 means your request already reached the site’s servers. If the domain name system were failing you, you’d see a “server not found” error instead.

If the site is down for everyone, there’s nothing to fix on your side. Wait, or contact the site’s administrators.

If it’s your site: confirm it isn’t only you

Before you change any settings, confirm the error is real and repeatable. Test from outside your office network, for example with your phone on mobile data or with an uptime monitor’s check. Then time the failure:

curl -o /dev/null -s -w 'status=%{http_code} time=%{time_total}s\n' https://example.com/slow-page/

Time the failure first

If the 504 always shows up after about 30, 60 or 120 seconds, a specific layer’s default timeout is cutting the request off. Write the number down. It tells you where to look first.

504 vs 502 vs 503 vs 524: which error do you have?

Request Chain Timeout Diagram

These four look alike but point to different problems. A 504 means the upstream server was too slow. A 502 means the upstream sent a broken response or refused the connection. A 503 means the server says it’s temporarily unavailable. A 524 is Cloudflare’s own code for “the origin connected but never answered.”

Code Meaning Who generates it Typical cause First check
502 Bad Gateway Upstream sent an invalid response or refused the connection nginx, Apache, CDN, load balancer PHP-FPM crashed or isn’t running, wrong socket path, a worker killed mid-request Is the PHP-FPM or app service running?
503 Service Unavailable Server is temporarily unable to handle the request Origin, host or load balancer Maintenance mode, rate limits, no healthy targets, host resource limits Maintenance flags, host limits, target health
504 Gateway Timeout Gateway got no timely response from upstream nginx, Apache, ALB, CloudFront, Vercel Slow PHP, slow queries, slow external APIs, all workers busy Proxy error log and request timing
524 A Timeout Occurred Cloudflare connected to the origin but got no HTTP response in time Cloudflare only Long-running origin process beyond 120 seconds Origin logs for requests over 120 seconds

504 vs 502 Bad Gateway

A 502 is about a bad answer, and a 504 is about no answer in time. If nginx can’t connect to PHP-FPM at all, you get a 502. If it connects and PHP-FPM is still working when the timer runs out, you get a 504. One overlap is worth knowing: when PHP-FPM’s request_terminate_timeout kills a slow worker, nginx usually reports a 502, because the connection is reset rather than left waiting. For crashed services and socket errors, see our guide on the 502 bad gateway error.

504 vs 503 Service Unavailable

A 503 means the server is currently unable to handle the request, commonly because of temporary overload or maintenance. The server or load balancer knows it can’t serve you right now, because of maintenance, rate limiting or no healthy backends. A 504 means a gateway or proxy did not receive a timely response from an upstream server; it does not establish that the upstream server accepted the request.

Cloudflare 524 vs a 504 that passes through Cloudflare

According to Cloudflare’s documentation, a 524 means Cloudflare connected to your origin, but the origin sent no HTTP response before the default 120-second Proxy Read Timeout. Many older guides still say 100 seconds, but the current docs say 120. Cloudflare’s docs also say that when a 502 or 504 page doesn’t mention Cloudflare, the error came from your host or origin and passed straight through. If you’re behind Cloudflare and see a plain 504, the timeout happened at your server or load balancer, not at Cloudflare.

Read the error page before the dashboard

If the error page doesn’t carry Cloudflare branding, open your server logs, not the Cloudflare dashboard. The origin or your host produced that 504.

Find the layer that timed out

Find the layer that timed out
Illustration

You find the layer that gave up by combining three clues: the error page’s wording, the response headers, and the matching log line or metric. The table below lists each layer’s documented default, which works as a lookup chart for the number you timed.

Layer Default timeout Error you see Setting to change Can you change it?
Cloudflare (proxied) 120 s read, 30 s write Cloudflare-branded error 524 Proxy Read Timeout (Cache Rules) Read: Enterprise only, up to 6,000 s. Write: no
Amazon CloudFront 30 s origin response timeout 504 “Generated by cloudfront” Origin settings, Response timeout Yes, up to 60 s; more needs a quota increase
AWS Application Load Balancer 60 s idle timeout 504, counted in HTTPCode_ELB_504_Count Load balancer attribute: Idle timeout Yes
nginx 60 s (proxy_read_timeout, fastcgi_read_timeout) Plain “504 Gateway Time-out” page Those directives in the server or location block Yes, on a VPS or dedicated server
Apache (mod_proxy) 60 s (Timeout; ProxyTimeout inherits it) “The gateway did not receive a timely response” ProxyTimeout or Timeout Yes, on a VPS or dedicated server
PHP max_execution_time 30 s in the production php.ini Fatal “Maximum execution time exceeded” (usually a 500) php.ini, pool config or host panel Usually yes
PHP-FPM request_terminate_timeout 0 (off) Worker killed; nginx usually returns 502 Pool file, for example www.conf VPS yes, managed hosts on request
Vercel Functions (fluid compute) 300 s 504 FUNCTION_INVOCATION_TIMEOUT maxDuration, vercel.json or the dashboard Hobby up to 300 s; Pro and Enterprise can set longer limits

Reading the error page and headers

Fetch only the headers and look for each layer’s fingerprint:

curl -sI https://example.com/slow-page/
  • server: cloudflare and a cf-ray ID: the request went through Cloudflare. Note the Ray ID for support tickets.
  • x-cache: Error from cloudfront and x-amz-cf-id: CloudFront produced or passed on the error.
  • server: awselb/2.0: the AWS load balancer generated the response itself.
  • server: nginx or server: Apache: your web server answered.
  • x-vercel-id, sometimes with x-vercel-error: FUNCTION_INVOCATION_TIMEOUT: a Vercel function hit its limit.

Reading nginx and PHP-FPM logs

People often ask what “upstream timed out (110: Connection timed out) while reading response header from upstream” means. It’s the most common 504 log line. nginx connected to PHP-FPM or the app, but didn’t receive response headers within the read timeout. The upstream: and request: fields in that line tell you which backend and which URL were involved.

[error] upstream timed out (110: Connection timed out) while reading response header from upstream,
client: 203.0.113.7, server: example.com, request: "POST /wp-admin/admin-ajax.php HTTP/2.0",
upstream: "fastcgi://unix:/run/php/php8.4-fpm.sock"

On the PHP-FPM side, look for these:

What you see What it means Fix
upstream timed out (110) ... while reading response header PHP or the app took longer than nginx’s read timeout Find the slow code first, then line up timeouts
upstream timed out (110) ... while connecting to upstream nginx couldn’t even open a connection to the backend Check that the backend is running and the firewall allows it
server reached pm.max_children setting (5), consider raising it Every PHP-FPM worker was busy, so new requests queued Fix slow requests, then size pm.max_children to RAM
execution timed out (...) terminating PHP-FPM killed a worker at request_terminate_timeout Read the slowlog trace for that request
cURL error 28: Operation timed out in WordPress An outbound HTTP call (an API, or WP-Cron’s loopback request) timed out Check the remote API, DNS and outbound firewall rules
Fails at exactly 30 s, 60 s or 120 s A layer’s default limit Match the number against the defaults table

The nginx log usually lives at /var/log/nginx/error.log. PHP-FPM logs to a path such as /var/log/php8.4-fpm.log, depending on your distribution.

CDN and load balancer metrics

On AWS, open CloudWatch for the Application Load Balancer and compare two metrics. HTTPCode_ELB_504_Count counts 504s the load balancer generated itself. HTTPCode_Target_5XX_Count counts errors your servers returned.

Did you know?

According to AWS’s re:Post Knowledge Center, if the HTTPCode_ELB_504_Count metric has no data, the load balancer didn’t produce your 504s. Your application servers did.

A timeout that always hits the same number points to a layer limit

Random slowness produces random failure times. A request that fails at the same second every time is hitting a configured limit. A WordPress.org support thread describes a WooCommerce checkout AJAX call that takes exactly 30 seconds and returns a 504 every time, while the rest of the site works. Thirty seconds matches CloudFront’s default, a host’s proxy limit, or PHP’s default max_execution_time, although PHP’s limit normally ends in a fatal error and a 500 rather than a 504. Sixty seconds points to nginx, Apache or an ALB. A Cloudflare-branded error at 120 seconds is a 524.

How to fix a 504 on WordPress

HTTP Error Codes Comparison Table

On WordPress, a 504 usually comes from one slow request (a plugin, an admin-ajax.php call or a heavy query) or from all PHP workers being busy at once. Work through the steps in order, because the early ones are cheap and rule out the most.

What you need before you start:

  • A full backup of files and database, taken by your host or a backup plugin, stored off the server.
  • SFTP or SSH access, plus WP-CLI if your host provides it.
  • Access to the server’s nginx/Apache error log and the PHP error log (in the hosting panel or over SSH).
  • The URL that fails, the time it failed (with time zone) and how many seconds it took.

Security note

Back up the files and the database before you change any plugin, PHP version or server setting. A failed update or a wrong directive can take the whole site offline, and a backup is the only quick way back.

Fix order for WordPress

  1. Check your host’s status page for an ongoing incident.
  2. Open the web server and PHP error logs at the time of the failure.
  3. Turn on the PHP-FPM slowlog, or install Query Monitor, to find the slow code.
  4. Deactivate plugins, then switch the theme, to isolate the cause.
  5. Find and calm heavy admin-ajax.php and Heartbeat API requests.
  6. Clean up and index the database.
  7. Move to a supported PHP version (WordPress 7.0 needs 7.4 or later).
  8. Ask your host about PHP worker limits and upgrade the plan if you keep hitting them.

When wp-admin itself returns 504

If the dashboard won’t load, you can’t deactivate plugins from it. Do it from the command line or over SFTP:


wp plugin deactivate --all wp plugin activate woocommerce

Without WP-CLI, rename wp-content/plugins to plugins-off over SFTP. WordPress then treats every plugin as missing. If the 504 stops, rename the folder back and disable plugins one by one by renaming their individual folders. Do the same with the active theme folder to fall back to a default theme.

Builder tip

Before deactivating everything on a live store, run wp plugin list --status=active > active-plugins.txt so you can restore the exact set afterwards.

Plugins, admin-ajax and the Heartbeat API

A lot of WordPress 504 log lines point to POST /wp-admin/admin-ajax.php. That endpoint handles background requests from plugins, page builders and the Heartbeat API, which polls the server on a timer while the dashboard or editor is open. Query Monitor shows which plugin owns a slow AJAX action and which database queries it ran. Typical offenders are related-posts plugins that run large queries, statistics plugins that write on every request, and backup or security scans running during the day.

For Heartbeat, reduce the polling frequency or limit it to the post editor. Several performance plugins offer this setting. Don’t switch it off entirely, because the editor uses it for autosave and post locking.

Slow database queries

Long-running MySQL/MariaDB queries are a major cause of 504s on large sites. Look for:

  • An oversized wp_options table with large autoloaded rows. WordPress loads those on every request.
  • Bloated wp_postmeta tables on stores with many products or orders.
  • Leftover tables from deleted plugins, and thousands of expired transients.
  • Table locks during backups or imports, which make every other query wait.

Enable the MySQL slow query log (slow_query_log = 1, long_query_time = 2) on a VPS, or ask your host for slow-query data. Fix the query or add an index before you raise any timeout.

PHP version and PHP workers

WordPress 7.0 “Armstrong”, released May 20, 2026, raised the minimum PHP version from 7.2.24 to 7.4. The WordPress Hosting Team handbook recommends PHP 8.4 or 8.5 for new installs. Newer PHP runs the same code faster, which gets requests under the timeout. Test the upgrade on a staging copy first, because old plugins sometimes break on PHP 8.x.

Each PHP worker handles one request at a time. If a host gives you four workers and four visitors trigger a slow page, the fifth request waits in the queue and can hit nginx’s 60 seconds before it even starts. Ask your host how many PHP workers your plan includes and whether its logs show the pool maxing out.

Firewalls and security plugins

Security plugins and web application firewalls can slow every request if they do heavy scanning or call outside services. Server firewalls can also block outbound calls to a payment gateway or licence server, so PHP waits until its own HTTP timeout runs out. That’s often what’s behind “cURL error 28”. If isolating plugins points to a security plugin, check its scan schedule and its external lookup settings before you remove it.

WooCommerce: 504s at checkout, on imports and in bulk actions

WooCommerce: 504s at checkout, on imports and in bulk actions
Illustration

WooCommerce adds three common 504 triggers: slow payment gateway calls during checkout, a backlog of Action Scheduler jobs, and large imports or bulk edits that run in one request.

Checkout and payment gateway timeouts

Checkout sends an AJAX request that creates the order and calls the payment gateway’s API while the customer waits. If the gateway or a fraud-check service responds slowly, the whole request can exceed a proxy limit. If it fails at a fixed 30 seconds every time while the rest of the store works, look at the proxy layers first (CloudFront, your host’s proxy, a load balancer). Then check the WooCommerce logs under WooCommerce > Status > Logs for gateway errors. Fixing the slow external call is the real fix. Raising the proxy timeout only makes the customer wait longer.

Action Scheduler backlogs and WP-Cron

Action Scheduler is the job queue WooCommerce and many plugins use for webhooks, emails, subscription renewals and analytics. Open WooCommerce > Status > Scheduled Actions and filter by Pending. Community reports describe more than 450 pending tasks, where running them manually from that screen returned 502 or 504. That’s expected: clicking “Run” there processes the job inside a normal web request, with the same timeouts.

By default, WP-Cron runs when visitors load pages, so a big backlog makes ordinary page loads slow and can take down the admin panel. Switch to a real server cron and work through the queue from the command line, where web timeouts don’t apply:

// wp-config.php
define( 'DISABLE_WP_CRON', true );
# crontab -e : run due WP-Cron events every 5 minutes
*/5 * * * * cd /var/www/example.com && wp cron event run --due-now --quiet

# Clear an Action Scheduler backlog in batches
wp action-scheduler run --batch-size=25

If one hook keeps failing, find the plugin that registers it before you clear the backlog, or the queue will fill up again.

Imports, exports and bulk edits

If you get a 504 only when importing products or running bulk edits, that’s a timeout problem, not a broken store. A 5,000-row CSV import or a bulk price change across thousands of variations can run longer than any web timeout. Split the file into smaller batches, use an importer that processes rows in the background, or run the job with WP-CLI over SSH. This is one of the few cases where temporarily raising a timeout on an admin-only path makes sense.

Fixing 504s on nginx and PHP-FPM (VPS and self-managed)

Fixing 504s on nginx and PHP-FPM (VPS and self-managed)
Illustration

On your own server, two jobs fix 504s for good: make the slow request faster, and set timeouts so each inner layer is shorter than the one outside it. When PHP fails first, you get a clear PHP error and a stack trace. When the CDN fails first, you get a generic 504 or 524 and no clue where the time went.

The order to keep:

  1. PHP max_execution_time and PHP-FPM request_terminate_timeout (innermost, shortest)
  2. nginx fastcgi_read_timeout or proxy_read_timeout
  3. Load balancer idle timeout
  4. CDN timeout (outermost, longest)

Worked example: a site behind Cloudflare (120 s, fixed below Enterprise) and an AWS ALB (60 s default). Set PHP max_execution_time to 45, request_terminate_timeout to 50s and nginx fastcgi_read_timeout to 55s, and leave the ALB at 60. A runaway request now fails inside PHP at 45 to 50 seconds and leaves a slowlog trace. Nothing reaches the outer layers’ limits.

fastcgi_read_timeout and proxy_read_timeout

Both default to 60 seconds. Use fastcgi_read_timeout when nginx talks to PHP-FPM directly, and proxy_read_timeout when nginx proxies to Node.js, another server or a container.

# PHP-FPM (typical WordPress)
location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.4-fpm.sock;
    fastcgi_read_timeout 55s;
}

# Reverse proxy to an app (Next.js, Node, a container)
location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_connect_timeout 5s;
    proxy_read_timeout 55s;
}

Test the configuration before you reload. A syntax error stops nginx from reloading:

sudo nginx -t && sudo systemctl reload nginx

Did you know?

As Baeldung’s nginx timeout guide explains, proxy_read_timeout doesn’t cap total response time. It measures the gap between two reads from the upstream, so a response that keeps streaming data can run well past 60 seconds without a 504.

PHP max_execution_time and request_terminate_timeout

max_execution_time is set in php.ini, or as php_admin_value[max_execution_time] in the pool file. PHP’s manual notes a catch on Linux: time spent outside the script itself, such as database queries, stream operations and system calls, doesn’t count toward this limit. A script that waits two minutes for a slow API or a locked table can sail past a 30-second max_execution_time. That’s why request_terminate_timeout matters. It’s a wall-clock limit in the PHP-FPM pool, and it’s off (0) by default.

; /etc/php/8.4/fpm/pool.d/www.conf
request_terminate_timeout = 50s
request_slowlog_timeout = 10s
slowlog = /var/log/php8.4-fpm-slow.log

Restart PHP-FPM after the change (sudo systemctl restart php8.4-fpm). The slowlog then records a stack trace for any request running longer than 10 seconds. That trace names the exact plugin function or query that’s slow.

PHP-FPM worker exhaustion

If the log shows server reached pm.max_children setting, requests are queuing for a free worker. The common default in www.conf is just 5. To size it, divide the RAM you can give PHP by the average memory of one PHP-FPM process (check with ps or top). For example, 2 GB for PHP divided by about 80 MB per process allows roughly 25 children. Going higher than that risks swapping, which makes everything slower. Raising workers helps under traffic spikes. If each request is slow, more workers just let more slow requests run at once.

When raising the timeout is the right fix and when it hides the problem

Raise it for work that is legitimately long and rare: imports, exports, backups, report generation and admin-only migrations. Scope the higher limit to those paths, for example a separate location block for /wp-admin/admin-ajax.php or an import endpoint, rather than the whole site.

Don’t raise it for normal page loads. If a product page takes 70 seconds, a 120-second timeout swaps the 504 for a 70-second wait that visitors will abandon, and those slow requests keep PHP workers busy for everyone else. The honest counter-argument is that a quick timeout increase can stop the bleeding during a sale or launch. That’s fine as long as you treat it as temporary and keep looking for the slow query or API call.

Common mistakes:

  • Raising the nginx timeout while a load balancer or CDN in front still cuts off at 60 or 120 seconds.
  • Changing php.ini when PHP-FPM reads a different file (check with php-fpm8.4 -i | grep "Loaded Configuration").
  • Editing nginx without running nginx -t, then reloading a broken config.
  • Blaming .htaccess. A broken .htaccess usually produces a 500, not a 504.

Behind Cloudflare, AWS or another CDN

A CDN or load balancer adds its own timeout on top of your server’s. By default, Cloudflare stops waiting after 120 seconds and shows a 524. An AWS ALB stops after 60 idle seconds. CloudFront waits 30 seconds by default.

Cloudflare

Cloudflare’s documentation lists a 120-second Proxy Read Timeout, which produces a 524. There’s also a 30-second Proxy Write Timeout (6.5 seconds for Cloudflare Images) that also produces a 524 and can’t be changed on any plan. Enterprise customers can raise the read timeout to as much as 6,000 seconds, for example with the Proxy Read Timeout setting in a Cache Rule. Changing max_execution_time or proxy_read_timeout on your server does nothing for a 524, because Cloudflare is the layer giving up.

On Free, Pro and Business plans, the standard workaround for long admin jobs is to send them to a DNS-only (grey-cloud) subdomain such as long.example.com, which skips the Cloudflare proxy. That subdomain also skips Cloudflare’s protection and exposes your origin IP, so restrict it to logged-in admins or an IP allowlist. A better long-term fix is to run the job in the background and have the browser poll for progress.

AWS Application Load Balancer

The ALB idle timeout defaults to 60 seconds and lives under the load balancer’s Attributes in the EC2 console. AWS’s Knowledge Center describes a less obvious cause: the backend closes its TCP connection before the ALB’s idle timeout ends. The fix is to enable keep-alive on the backend and set its keep-alive timeout higher than the ALB idle timeout. nginx’s default keepalive_timeout of 75s already meets that rule. Apache’s default KeepAliveTimeout of 5 seconds does not, so raise it above 60 on Apache targets behind an ALB.

Amazon CloudFront

CloudFront’s default origin response timeout is 30 seconds. You can change it under the origin’s settings (Response timeout), up to 60 seconds without a quota increase. Above 60 seconds, you have to request an increase in Service Quotas and then update the origin yourself, because the quota change doesn’t apply automatically. Since July 2025, you can also set custom response timeouts for S3 origins. A WooCommerce checkout that fails at exactly 30 seconds behind CloudFront fits this limit.

Headless CMS and serverless front ends (Vercel, Next.js)

On Vercel, a function that doesn’t respond within its maximum duration returns a 504 with the code FUNCTION_INVOCATION_TIMEOUT. Vercel’s docs say that with fluid compute, which is on by default, Node.js, Bun and Python functions default to 300 seconds on every plan. Hobby is capped at 300 seconds. Pro and Enterprise can configure longer limits.

You set the limit per route in a Next.js route segment config, in vercel.json, or as a project default under the project’s Functions settings in the dashboard:

// app/api/revalidate/route.ts (Next.js App Router)
export const maxDuration = 120; // seconds

If a Pro project still times out at 60 seconds, as some community threads report, look for an explicit maxDuration or vercel.json override, a project-level default set lower, or a project that isn’t running on fluid compute.

For headless WordPress or another headless CMS, the slow part is usually the CMS API call, not the function. Cache CMS responses with Incremental Static Regeneration (ISR) or a data cache, so visitors don’t wait on the CMS for every page view. Move rebuilds, search indexing and image processing to background jobs or webhooks. A function that waits on a slow origin still uses up your duration budget.

Shopify and other hosted platforms

On Shopify and similar hosted platforms, you can’t touch the server or its timeouts. Your job is to confirm whether the platform is having an incident, rule out your apps and theme code, and give support enough detail to act. Because the Shopify ecommerce platform is fully hosted, a store-wide 504 is usually on Shopify’s side and shows up on the Shopify Status page.

Use these clues:

  • Storefront fails, admin works: suspect a theme customisation, an app embed or an app proxy that calls a slow external server. Preview the theme with app embeds turned off in the theme editor, or preview an unmodified copy of the theme.
  • Admin and storefront both fail: check Shopify Status and wait for the incident to clear.
  • Only one app page fails: the app’s own servers are timing out. Contact the app developer, not Shopify.

The same logic applies to Squarespace, Wix and other builders. Check the status page, remove recent scripts or integrations, then contact support with timestamps.

Preventing 504s

Preventing 504s
Illustration

You prevent most 504s by making requests shorter and rarer: cache what you can, move long work into queues, keep the database healthy, and line up timeouts so failures show up where you can read them.

  • Page caching (a host cache, nginx FastCGI cache or a CDN) serves most visitors without touching PHP at all.
  • Object caching with Redis or Memcached cuts repeated database queries on WooCommerce and membership sites.
  • Uptime monitoring with alerts catches 504s before customers report them. Track response time too, not just up or down.
  • Background queues (Action Scheduler, a real server cron, serverless background jobs) for imports, emails and syncs.
  • Database upkeep: clean autoloaded options, remove orphaned tables, keep the slow query log on.
  • Aligned timeouts: PHP shorter than nginx, nginx shorter than the load balancer, the load balancer shorter than the CDN.

Expected result: after the fixes, the failing URL returns a 200 in a normal time (a few seconds for page loads), the nginx error log no longer shows “upstream timed out” lines for it, and the PHP-FPM log stops reporting pm.max_children warnings at peak times.

When to upgrade your hosting

Upgrade when the code is reasonably efficient and you still run out of capacity. Clear signs are daily pm.max_children warnings, 504s that track traffic peaks rather than specific pages, a shared host throttling CPU during sales, or a plan with too few PHP workers for your traffic. If one admin page or one plugin causes every 504, a bigger plan only postpones the problem. Our comparison of web host options covers what to look for in PHP workers and limits.

What to send your host (template)

Support teams fix things faster when they can find the exact request in their logs. Copy and fill in:

Subject: Recurring 504 Gateway Time-out on example.com

URL(s): https://example.com/checkout/ (POST /?wc-ajax=checkout)
Times (with time zone): 2026-11-23 14:02:10 UTC, 14:05:44 UTC, 14:11:03 UTC
Time to failure: always about 60 seconds
Error page wording: plain "504 Gateway Time-out" / nginx (no Cloudflare branding)
Request IDs: cf-ray 8f1a2b3c4d5e6f70-IAD (if behind Cloudflare)
Log lines: upstream timed out (110: Connection timed out) while reading response header from upstream ...
What we ruled out: all plugins disabled on staging, PHP 8.4, no recent changes since Nov 20
Questions: Which layer returned the 504? How many PHP workers does our plan have,
and did we hit the limit at these times?

The best next step is to time the failing request today and match the number against the defaults table. That number tells you which layer to fix first.

FAQ

What is a 504 gateway time-out?

It’s an HTTP status code defined in RFC 9110, section 15.6.5. A server acting as a gateway or proxy, such as nginx, a load balancer or a CDN, didn’t get a timely response from the upstream server it needed to complete your request.

Is error 504 my fault?

Almost never, if you’re a visitor. The failure happens between the website’s own servers. Try another device or network and turn off your VPN. If the site still fails from every network you try, the cause is on the server side and may need action from the site’s administrators or its hosting provider.

What is the difference between 504 and 502 errors?

A 502 means the upstream server sent an invalid response or refused the connection, often because PHP-FPM or the app crashed. A 504 means the gateway or proxy didn’t get a timely response from the upstream server before its timeout.

How do I fix 502 bad gateway?

Check that the backend service (PHP-FPM, Node.js or the app container) is running, that nginx points to the right socket or port, and that the backend isn’t crashing or being killed for using too much memory. The web server’s error log usually names the exact connection failure.

How long does a 504 gateway timeout last?

A 504 caused by a short overload often clears within a few minutes. One caused by a slow query, a bad plugin or mismatched timeouts lasts until someone fixes it, and it usually comes back at the same times of day.

Can a 504 error be caused by my internet or router?

Rarely. Your request has to reach the site’s servers before a 504 can be generated. The exceptions are a VPN, a corporate proxy or a security product that acts as a gateway and times out itself.

How do I fix a 504 gateway timeout in WordPress?

Back up first. Then check the server logs, use Query Monitor or the PHP-FPM slowlog to find slow code, and deactivate plugins (with WP-CLI if wp-admin won’t load). After that, optimise the database, move to PHP 8.4 or later, and ask your host about PHP worker limits.

How do I fix 504 Gateway Time-out in nginx?

Read /var/log/nginx/error.log for “upstream timed out (110)” lines to find the slow URL, and fix the slow request. If the work is legitimately long, raise fastcgi_read_timeout or proxy_read_timeout above the 60-second default for that location only. Run nginx -t and then reload. If an operation over 60 seconds always fails, that default is the cause.

What is the difference between Cloudflare error 524 and 504?

A 524 is Cloudflare’s own code. It means Cloudflare connected to your origin, but no HTTP response arrived within its 120-second read timeout. A 504 that passes through Cloudflare without Cloudflare branding was produced by your host, load balancer or web server.

Should I just increase the timeout to fix a 504?

Only for rare, long admin tasks like imports, exports and backups, and only on those paths. For everyday pages, a longer timeout turns the error into a long wait and keeps PHP workers busy. Find the slow query, plugin or API call instead.

About this article

Written by

Writer: WordPress, Hosting & Domains, SEO & Performance

Carla Dunmore covers WordPress, hosting and domains, SEO and performance, and plugin security alerts, working from official documentation, changelogs, vendor advisories and public vulnerability databases. She checks which versions are affected and whether a fix has actually shipped before labelling an alert, and she cares most about giving site owners clear, prioritised steps they can act on.

  • Fact-checked by Moira Hensley against the sources listed below before publication.
  • Published
Sources (8)
  1. 504 Gateway Timeout - MDN Web Docs (developer.mozilla.org)
  2. Cloudflare error 524 (developers.cloudflare.com)
  3. Cloudflare error 502 and 504 (developers.cloudflare.com)
  4. nginx timeouts - Baeldung (baeldung.com)
  5. Fix 504 Gateway Timeout error in nginx - Linuxize (linuxize.com)
  6. Troubleshoot 504 errors with an Application Load Balancer - AWS re:Post (repost.aws)
  7. Amazon CloudFront introduces new origin response timeout controls (aws.amazon.com)
  8. Increase CloudFront custom origin response timeout - AWS re:Post (repost.aws)