Cannot connect to the backend
- Status
- 503
- Log message in the httpd source
failed to make connection to backend
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.
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.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
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.failed to make connection to backendError dispatching request to ...pass request body failedmod_reqtimeoutTimeoutmod_proxyProxyTimeoutTimeouttimeout on a workerProxyTimeoutconnectiontimeout on a workerretry on a workermax_execution_timerequest_terminate_timeoutThe ProxyTimeout docs describe the use case directly: useful with "a slow/buggy appserver which hangs", when you would rather return a timeout than wait. The same value governs every worker that does not set its own timeout.
ProxyPass "/app/" "http://127.0.0.1:8000/" connectiontimeout=5 timeout=120
ProxyPassReverse "/app/" "http://127.0.0.1:8000/"<FilesMatch "\.php$">
SetHandler "proxy:unix:/run/php/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
<Proxy "fcgi://localhost/" enablereuse=on max=10 timeout=120>
</Proxy>ProxyTimeout 120SetHandler 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.
LogLevel warn proxy:debugRun 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.
LogLevel accepts a module prefix, so LogLevel warn proxy:debug raises only mod_proxy. Reload with apachectl graceful, repeat the request, then restore it.
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.
A CDN in front can time out first. See Cloudflare 504 if the error page is not Apache's.
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.
3 questions people ask next, answered from the sources on this page.
ProxyTimeout defaults to the value of Timeout, which is 60 seconds. A ProxyPass timeout parameter overrides it for that worker.
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.
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.
Run the free audit, then approve the fixes. Every change can be undone.