MockFoxAdvertise

HTTP 504 Gateway Timeout

Updated Free mock REST & WebSocket APIs

HTTP 504 Gateway Timeout — A gateway or proxy didn't get a response from the upstream server in time.

Class
5xx Server Error
Defined in
RFC 9110 §15.6.5
Official
Yes (IANA registry)
Cacheable by default
No (unless Cache-Control/Expires say so)
Safe to retry
Yes, after a delay (respect Retry-After)

Try it: get a real 504 response

Our test endpoint answers every request with 504 Gateway Timeout.

curl -i https://mockfox.dev/api/status/504

Use it in tests, health-check monitors or to see how your client handles a 504. Add ?delay=2000 to slow it down.

What does HTTP 504 mean?

504 Gateway Timeout means a server acting as a gateway or proxy didn't receive a timely response from the upstream server it needed to complete the request. The connection to the upstream may have worked, but the answer took too long.

Each layer has its own timeout: browsers wait minutes, but nginx defaults to 60 seconds, AWS ALB to 60 seconds, API Gateway to 29 seconds and Cloudflare to 100 seconds (which shows its own 524).

When is 504 used?

  • Slow database queries or reports that run longer than the proxy timeout.
  • An upstream service (payment provider, third-party API) hanging.
  • Serverless functions exceeding their maximum duration.
  • Network problems between proxy and backend (packet loss, firewall dropping traffic).

Common causes of a 504

  • Long-running work done synchronously in the request.
  • Database locks, missing indexes, or connection pools waiting for a free connection.
  • An overloaded backend queueing requests.
  • DNS resolution problems for the upstream hostname.

How to fix 504 Gateway Timeout

If you're visiting the site

  1. Reload after a minute; the server may be under heavy load.
  2. If submitting something important (a payment), check whether it went through before retrying, to avoid duplicates.
  3. Try later or check the site's status page.

If you run the site or API (developers)

  1. Find the slow part: proxy logs show which upstream timed out; APM traces show where time went.
  2. Optimise queries (indexes, pagination) and add timeouts to outbound calls so they fail fast.
  3. Move long jobs to a background queue and return 202 with a status URL.
  4. Raise proxy timeouts only as a last resort, keeping them consistent across layers.

Returning or handling 504: server examples

nginx

location /api/ {
    proxy_pass http://app;
    proxy_connect_timeout 5s;
    proxy_read_timeout 120s;   # default 60s — time between two reads
    proxy_send_timeout 120s;
}

Express

// Fail fast on slow dependencies instead of hanging until the proxy gives up
const res = await fetch(PAYMENTS_URL, { signal: AbortSignal.timeout(10_000) });

Next.js

// app/api/report/route.ts — raise the function duration on serverless hosts
export const maxDuration = 60; // seconds

export async function POST() {
  const job = await queue.enqueue("report"); // better: do it in the background
  return Response.json({ jobId: job.id }, { status: 202 });
}

Example 504 response

HTTP/1.1 504 Gateway Timeout
Server: nginx
Content-Type: text/html

<html><head><title>504 Gateway Time-out</title></head><body><center><h1>504 Gateway Time-out</h1></center></body></html>

Related status codes

Related tools

Frequently asked questions

How do I fix 504 Gateway Timeout?

As a visitor, wait and retry. As the owner, find what's slow (database, external API, heavy computation), make it faster or asynchronous, and align timeouts between proxy and app.

What's the difference between 504 and 502?

502: the upstream returned an invalid response or the connection failed. 504: the upstream didn't respond before the proxy's timeout.

What's the difference between 504 and 408?

408 is the server timing out on a slow client sending its request. 504 is a proxy timing out on a slow server producing its response.