Free auditStart free
GuideError · HTTP status codes

504 Gateway Timeout in Apache

Fix an Apache 504 behind mod_proxy or PHP-FPM: which of Timeout, ProxyTimeout and worker timeout applies, why a refused connection is a 503, and how to log it.

4 min
read
10
sources
Oct 29, 2026
updated
Scaplet Editorial Team
author
The short answer

Apache returns 504 when mod_proxy or mod_proxy_fcgi waits too long for the backend. The wait is governed by ProxyTimeout, which defaults to the value of Timeout (60 seconds), or by a timeout parameter on the ProxyPass worker. A backend that refuses or fails the connection gives 503, not 504, so the status tells you which phase failed.

  1. What decides a 504 in Apache
  2. Timeouts that apply
  3. Fix by backend type
  4. Reproduce and read the evidence
  5. SEO and crawler notes
30-second check

Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode
01Backend problem and the status Apache sends

What decides a 504 in Apache

RFC 9110 says a 504 means the server, "while acting as a gateway or proxy, did not receive a timely response from an upstream server". In Apache the gateway is mod_proxy with mod_proxy_http or mod_proxy_fcgi. The httpd source maps a timed-out read from a FastCGI backend to a 504 and logs Error dispatching request to ... (AH01075). A failure to open the connection takes a different path: failed to make connection to backend (AH01079 for FastCGI, AH01114 for HTTP) returns 503.
Phase

Cannot connect to the backend

Status
503
Log message in the httpd source
failed to make connection to backend
Phase

Backend accepted but did not answer in time (FastCGI)

Status
504
Log message in the httpd source
Error dispatching request to ...
Phase

Timeout while passing the request body to the backend

Status
504
Log message in the httpd source
pass request body failed
Phase

Client too slow sending its own request

Status
408
Log message in the httpd source
From mod_reqtimeout
03Fix it on your stack

Fix by backend type

Reverse proxy to an app: explicit worker timeouts
ProxyPass "/app/" "http://127.0.0.1:8000/" connectiontimeout=5 timeout=120
ProxyPassReverse "/app/" "http://127.0.0.1:8000/"
PHP-FPM through mod_proxy_fcgi, with a longer timeout for slow scripts
<FilesMatch "\.php$">
    SetHandler "proxy:unix:/run/php/php-fpm.sock|fcgi://localhost/"
</FilesMatch>

<Proxy "fcgi://localhost/" enablereuse=on max=10 timeout=120>
</Proxy>
Server-wide default for proxied requests
ProxyTimeout 120

SetHandler with a UNIX socket needs httpd 2.4.10 or later, and mod_proxy_fcgi disables connection reuse by default; enablereuse=on opts in. Do not raise timeouts blindly: a longer wait only helps when the work finishes eventually. If the real fix is a slow query or a hung process, set PHP limits that match, or the PHP side will stop first.

Raise the timeout when
  • A known long job finishes within a bound you can state
  • You also raised PHP-FPM and any CDN limit to match
  • The slow path is rare and the page is not user-critical
Fix the backend when
  • Requests hang on a lock, a query or an external call
  • Latency rises with load
  • The timeout you would need is longer than a CDN's own limit
04How it works

Reproduce and read the evidence

Raise only proxy logging
LogLevel warn proxy:debug
  1. 01

    Time the failing request

    Run curl -s -o /dev/null -w "%{http_code} %{time_total}s\n" https://example.com/slow. A 504 that arrives near 60 seconds points to the default Timeout or ProxyTimeout.

  2. 02

    Raise the proxy log level briefly

    LogLevel accepts a module prefix, so LogLevel warn proxy:debug raises only mod_proxy. Reload with apachectl graceful, repeat the request, then restore it.

  3. 03

    Hit the backend directly

    Request http://127.0.0.1:8000/slow or the FPM script on its own. If it is slow there, no Apache setting is the cause.

  4. 04

    Check for a CDN timeout

    A CDN in front can time out first. See Cloudflare 504 if the error page is not Apache's.

05Explained

SEO and crawler notes

Google lists 502 and 503 among the server errors that make its crawlers slow down; 5xx and 429 "prompt Google's crawlers to temporarily slow down with crawling". Persistent 5xx responses lead to dropped URLs, so fix long-running pages rather than hiding them. See 504 Gateway Timeout for the general case and 502 in Apache for the sibling error.

Sources · 10

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • rfc-editor.org
  • apache.org
  • githubusercontent.com
  • php.net
  • google.com
  1. 01RFC 9110: HTTP Semanticsrfc-editor.org · checked 2026-11-01
  2. 02Apache core: Timeout and LogLevelhttpd.apache.org · checked 2026-11-01
  3. 03Apache mod_proxy: ProxyTimeout and worker parametershttpd.apache.org · checked 2026-11-01
  4. 04Apache mod_proxy_fcgihttpd.apache.org · checked 2026-11-01
  5. 05Apache mod_reqtimeouthttpd.apache.org · checked 2026-11-01
  6. 06httpd source: modules/proxy/mod_proxy_fcgi.craw.githubusercontent.com · checked 2026-11-01
  7. 07httpd source: modules/proxy/mod_proxy_http.craw.githubusercontent.com · checked 2026-11-01
  8. 08PHP-FPM configurationphp.net · checked 2026-11-01
  9. 09PHP: php.ini directivesphp.net · checked 2026-11-01
  10. 10How HTTP status codes affect Google's crawlersdevelopers.google.com · checked 2026-11-01
Questions

Asked a lot.

3 questions people ask next, answered from the sources on this page.

01What is the default proxy timeout in Apache?

ProxyTimeout defaults to the value of Timeout, which is 60 seconds. A ProxyPass timeout parameter overrides it for that worker.

02Why do I get 503 instead of 504 when the backend is down?

In the httpd source, a failure to make the connection to the backend returns 503. A 504 comes after the connection exists but the backend does not answer in time.

03Does increasing PHP max_execution_time fix an Apache 504?

Only if PHP was the limit. The documented defaults are 30 for max_execution_time and Apache's 60 for proxy waits, so raise both together and keep them consistent.

Free · 2 minutes

Tools point. Agencies advise. This one ships.

Run the free audit, then approve the fixes. Every change can be undone.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane