# 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.

Canonical: https://scaplet.com/errors/http/504/apache

Guide Error · HTTP status codes

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

504 5xx · Server error

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](#what-decides-a-504-in-apache)
2. [Timeouts that apply](#timeouts-that-apply)
3. [Fix by backend type](#fix-by-backend-type)
4. [Reproduce and read the evidence](#reproduce-and-read-the-evidence)
5. [SEO and crawler notes](#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 with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F504%2Fapache%20(%22504%20Gateway%20Timeout%20in%20Apache%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F504%2Fapache%20(%22504%20Gateway%20Timeout%20in%20Apache%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F504%2Fapache%20(%22504%20Gateway%20Timeout%20in%20Apache%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F504%2Fapache%20(%22504%20Gateway%20Timeout%20in%20Apache%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

_01_Backend 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`

**503 versus 504 is a useful clue**If you expected a 504 from a dead backend and got a 503, that is by design in the proxy code. A 504 means the backend was reachable and silent. Log level for the HTTP read timeout message (AH01103) is `debug`.

_02_Documented timeouts

## Timeouts that apply

Setting

### `Timeout`

Default

60

What it controls

Time Apache waits for I/O in various circumstances, and the default for `mod_proxy`

Setting

### `ProxyTimeout`

Default

Value of `Timeout`

What it controls

Network timeout for proxied requests

Setting

### `timeout` on a worker

Default

`ProxyTimeout`

What it controls

Socket timeout in seconds for data sent by or to the backend

Setting

### `connectiontimeout` on a worker

Default

not stated

What it controls

Seconds Apache waits for the backend connection to be created

Setting

### `retry` on a worker

Default

60

What it controls

Seconds before a worker in error state is tried again

Setting

### PHP `max_execution_time`

Default

30

What it controls

PHP's own script time limit

Setting

### PHP-FPM `request_terminate_timeout`

Default

0 (off)

What it controls

Kills the worker serving a request after this time

The `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`.

_03_Fix it on your stack

## Fix by backend type

Reverse proxy to an app: explicit worker timeouts
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
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
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

_04_How 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](/errors/cdn/cloudflare-504) if the error page is not Apache's.

_05_Explained

## 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](/errors/http/504) for the general case and [502 in Apache](/errors/http/502/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. 01 [RFC 9110: HTTP Semantics](https://www.rfc-editor.org/rfc/rfc9110.html) rfc-editor.org · checked 2026-11-01
2. 02 [Apache core: Timeout and LogLevel](https://httpd.apache.org/docs/2.4/mod/core.html) httpd.apache.org · checked 2026-11-01
3. 03 [Apache mod_proxy: ProxyTimeout and worker parameters](https://httpd.apache.org/docs/2.4/mod/mod_proxy.html) httpd.apache.org · checked 2026-11-01
4. 04 [Apache mod_proxy_fcgi](https://httpd.apache.org/docs/2.4/mod/mod_proxy_fcgi.html) httpd.apache.org · checked 2026-11-01
5. 05 [Apache mod_reqtimeout](https://httpd.apache.org/docs/2.4/mod/mod_reqtimeout.html) httpd.apache.org · checked 2026-11-01
6. 06 [httpd source: modules/proxy/mod_proxy_fcgi.c](https://raw.githubusercontent.com/apache/httpd/trunk/modules/proxy/mod_proxy_fcgi.c) raw.githubusercontent.com · checked 2026-11-01
7. 07 [httpd source: modules/proxy/mod_proxy_http.c](https://raw.githubusercontent.com/apache/httpd/trunk/modules/proxy/mod_proxy_http.c) raw.githubusercontent.com · checked 2026-11-01
8. 08 [PHP-FPM configuration](https://www.php.net/manual/en/install.fpm.configuration.php) php.net · checked 2026-11-01
9. 09 [PHP: php.ini directives](https://www.php.net/manual/en/ini.list.php) php.net · checked 2026-11-01
10. 10 [How HTTP status codes affect Google's crawlers](https://developers.google.com/crawling/docs/troubleshooting/http-status-codes) developers.google.com · checked 2026-11-01

Questions

## Asked a lot.

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

_01_ What 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.

_02_ Why 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.

_03_ Does 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.

## Keep learning

[All errors](/errors)

[Learn 504 Gateway Timeout HTTP status codes](/errors/http/504) [Related 5xx server errors Status codes and links](/seo-issues/server-errors-5xx) [Read next 504 Gateway Time-out in nginx HTTP status codes](/errors/http/504/nginx) [Do Run a free site audit Free, about two minutes](/site-audit)

Other 504 errors
[Cloudflare 504 Gateway Timeout](/errors/cdn/cloudflare-504) [504 Gateway Time-out in nginx](/errors/http/504/nginx) [504 Gateway Timeout](/errors/http/504) [504 Gateway Timeout on IIS](/errors/http/504/iis) [ALB 504 Gateway Timeout](/errors/cdn/alb-504-gateway-timeout)

Nearby in errors
[503 Service Unavailable in WordPress](/errors/http/503/wordpress)

More in 504 Gateway Timeout
[504 Gateway Time-out in nginx](/errors/http/504/nginx) [504 Gateway Timeout in Apache](/errors/http/504/apache) [504 Gateway Timeout on IIS](/errors/http/504/iis)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

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

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
