504 Gateway Timeout: What Timed Out and How to Fix It
504 Gateway Timeout appears when a proxy or gateway gives up waiting for the server behind it. The request reached your app, but no answer arrived before the proxy's time limit, often 60 seconds. Slow database queries, calls to a slow outside API, and work that should run in the background are the usual causes.
| Layer | Default limit | What you see |
|---|---|---|
| Nginx proxy_read_timeout | 60 seconds between reads | 504 Gateway Time-out |
| AWS ALB idle timeout | 60 seconds | 504 from the load balancer |
| Amazon API Gateway (REST) | 29 seconds integration timeout | 504 Endpoint request timed out |
| Vercel function | Your plan's or maxDuration setting | 504 FUNCTION_INVOCATION_TIMEOUT |
| Cloudflare proxy | 100 seconds on most plans | Error 524, Cloudflare's own timeout code |
Updated
Raising a timeout is tempting and sometimes right, but it usually hides the real problem. A request that needs more than a minute will also be slow for every visitor, tie up a worker, and fail again under load. The better fix is to find why the request is slow, then make it fast or move it out of the request.
Measure first, then raise one limit
Time the slow request against the app
Run this on the server so the network is not part of the measurement.
curl -s -o /dev/null -w 'status %{http_code} in %{time_total}s\n' http://127.0.0.1:3000/reports/monthlyA longer timeout for one Nginx location
Scope the change to the slow path so the rest of the site keeps failing fast.
location /reports/ {
proxy_pass http://127.0.0.1:3000;
proxy_read_timeout 180s;
proxy_send_timeout 180s;
}
Fixes by platform
Nginx: proxy_read_timeout counts the time between two reads from the upstream, not the whole response, so streaming a little data keeps a long response alive. PHP behind Nginx has its own limits, max_execution_time and the FastCGI read timeout, and the lowest one wins.
Vercel: each function has a maximum duration set by your plan and the maxDuration option. Long tasks should hand off to a background job and let the page poll for the result.
Amazon API Gateway: REST APIs stop waiting for an integration after 29 seconds by default, so long work must be asynchronous: accept the job, return 202, and report the result later.
Make timeouts line up
When several layers each have a limit, the shortest one decides. A 120 second Nginx timeout does nothing behind a 60 second load balancer. List every layer from the browser to the database and make each timeout a little longer than the one inside it.
On a site hosted by We.Inc there is no web server, PHP process or function timeout of your own to tune. If a page on a We.Inc site returns this code, send support the address and the time so we can check our side.
How it works
- Find the exact URL that times out and how long it takes against the app directly.
- Check which layer cut it off: web server, load balancer, platform or CDN.
- Profile the slow request: database queries, outside API calls, large file work.
- Speed it up or move it to a background job; raise the one limit only if the work must stay in the request.
Tips
- Time the request with curl -w '%{time_total}' against the app's own address to separate app slowness from network trouble.
- Add timeouts to your own calls to outside APIs, shorter than the proxy's, so your app can return a clear error instead of a 504.
- Report generation, video processing and bulk email belong in a queue with a job status page, not in a web request.
- A database query that was fast with little data can slow down as tables grow; check for missing indexes first.
Frequently asked questions
What does 504 Gateway Timeout mean?
A server acting as a gateway or proxy did not get a timely response from the server it was forwarding to. The upstream may still finish the work, but the visitor gets the error.
How do I fix 504 Gateway Timeout in Nginx?
First make the slow endpoint faster. If it genuinely needs longer, raise proxy_read_timeout for that location only, for example to 180s, and check that any load balancer in front allows the same time.
Why does my Vercel function return 504?
It ran past its maximum duration, shown as FUNCTION_INVOCATION_TIMEOUT. Set maxDuration within your plan's limit, or split the work and run it in the background or a queue.
Is Cloudflare error 524 the same as 504?
It is Cloudflare's version of the same problem: Cloudflare connected to your server, but no HTTP response arrived within its timeout, 100 seconds by default. Fix the slow origin request, or move long jobs off the proxied path.
Can a visitor fix a 504?
No. Reloading may work if the slowness was brief. Repeating a form submission that timed out can create duplicates, so check whether the action went through first.
Related: 502 Bad Gateway, 503 Service Unavailable, Nginx errors, HTTP status codes.
Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.
More in Guides
- Abandoned Cart Email Examples and Templates
- Abandoned Cart Text Messages
- About Us Page Examples: 6 Annotated Designs for Small Businesses | How-to Guide
- How to Accept Payments on a Website
- An Accessibility Testing Process Web Teams Can Actually Keep Up | How-to Guide
- Accessible PDF Alternatives for Public Websites: When to Turn a PDF Into a Web Page | How-to Guide
- ADA Title II Website Deadline: April 2027 and April 2028 Explained | How-to Guide
- ADA Website Compliance for Small Businesses (2026 Guide) | How-to Guide
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App