# 502 Bad Gateway in Apache

> Fix an Apache 502 Bad Gateway: check ProxyPass targets, mod_proxy_fcgi sockets, worker error state, timeouts and keep-alive, with config you can copy.

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

Guide Error · HTTP status codes

Fix an Apache 502 Bad Gateway: check ProxyPass targets, mod_proxy_fcgi sockets, worker error state, timeouts and keep-alive, with config you can copy.

4 min

read

6

sources

Oct 25, 2026

updated

Scaplet Editorial Team

author

502 5xx · Server error

The short answer

In Apache httpd, a 502 Bad Gateway means mod_proxy or mod_proxy_fcgi passed the request to a backend (an app server or PHP-FPM) and did not get a valid response. Typical causes are a wrong ProxyPass target or socket, a backend that is down, or a pooled connection the backend already closed. Read the error log, then test the backend directly.

1. [What a 502 means when Apache sends it](#what-a-502-means-when-apache-sends-it)
2. [Causes specific to Apache and where to fix them](#causes-specific-to-apache-and-where-to-fix-them)
3. [Verify the fix](#verify-the-fix)

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%2F502%2Fapache%20(%22502%20Bad%20Gateway%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%2F502%2Fapache%20(%22502%20Bad%20Gateway%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%2F502%2Fapache%20(%22502%20Bad%20Gateway%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%2F502%2Fapache%20(%22502%20Bad%20Gateway%20in%20Apache%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

_01_Check it

## What a 502 means when Apache sends it

RFC 9110 defines 502 as the status for a gateway or proxy that "received an invalid response from an [inbound](/glossary/inbound-marketing) server". Apache httpd plays that role when you use `ProxyPass` (HTTP backends) or `SetHandler "proxy:fcgi://..."` (PHP-FPM and other FastCGI backends). What a 502 means in general, and the CDN versions of it, are on [502 Bad Gateway](/errors/http/502). This page covers what is specific to Apache. If you run nginx instead, use [502 Bad Gateway in nginx](/errors/http/502/nginx).

Apache writes the reason to its error log. The `ErrorLog` directive sets the file; the default is `logs/error_log` on Unix. Raise the proxy module's log level while you debug, then put it back.

Temporary proxy debug logging

```
# LogLevel takes [module:]level, so only the proxy module gets verbose LogLevel warn proxy:debug
```

First checks

```
# 1. Read the newest errors (path depends on your ErrorLog setting) sudo tail -n 50 /var/log/httpd/error_log # Debian/Ubuntu: /var/log/apache2/error.log # 2. Ask the backend directly, bypassing Apache curl -sSI http://127.0.0.1:8000/ # 3. Validate config and reload sudo apachectl configtest && sudo apachectl graceful
```

_02_Apache 502 causes

## Causes specific to Apache and where to fix them

Cause

### Wrong backend URL or socket

What to check

The target in `ProxyPass` or the path in `SetHandler "proxy:unix:/path/to/app.sock|fcgi://localhost/"`

Fix

Match it to where the backend listens. A Unix socket in `ProxyPass` needs httpd 2.4.7 or later; `SetHandler "proxy:unix:..."` needs 2.4.10 or later

Cause

### Backend is down or refusing connections

What to check

Whether the app or PHP-FPM is running; `curl` to the backend address

Fix

Start it. A TCP backend needs the host and port to match; a PHP-FPM pool's `listen` takes `ip.add.re.ss:port`, `port` or `/path/to/unix/socket`

Cause

### Unix socket not accessible to Apache

What to check

PHP-FPM `listen.owner`, `listen.group` and `listen.mode` for the socket

Fix

On Linux, access to the socket is controlled by those three settings, so the user Apache runs as must be allowed

Cause

### Worker stuck in the error state

What to check

`retry` (default 60 seconds), `failonstatus` and `failontimeout` on the `ProxyPass` line

Fix

While a worker is in the error state Apache sends no requests to that backend until `retry` expires, so a backend that is back can still look down. Lower `retry` or drop `failonstatus` codes you do not need

Cause

### Pooled connection already closed by the backend

What to check

HTTP backends, or FastCGI with `enablereuse=on` (mod_proxy_fcgi disables connection reuse by default): the backend's keep-alive timeout against `ttl` and `disablereuse`

Fix

`ttl` closes pooled connections that sit idle longer than that many seconds, so a value below the backend's keep-alive timeout avoids reusing a connection the backend has dropped. `disablereuse=On` closes the connection after every request; Apache documents it for firewalls that silently drop connections

Cause

### `mod_proxy_fcgi` not loaded

What to check

Apache modules list

Fix

It needs `mod_proxy` as well; both have to be present to handle FastCGI

Reverse proxy with explicit timeouts and connection pooling

```
ProxyPass "/app" "http://127.0.0.1:8000/" connectiontimeout=5 timeout=60 ttl=120 retry=10 ProxyPassReverse "/app" "http://127.0.0.1:8000/"
```

PHP-FPM over a Unix socket

```
<FilesMatch "\.php$"> SetHandler "proxy:unix:/run/php/php-fpm.sock|fcgi://localhost/" </FilesMatch>
```

**Timeouts are usually a 504, not a 502** `timeout` is the number of seconds Apache waits for data sent by or to the backend, and `connectiontimeout` is how long it waits for the connection to be created. RFC 9110 reserves 504 for a gateway that "did not receive a timely response". If the symptom is a slow backend rather than a refused or broken one, go to [504 Gateway Timeout](/errors/http/504).

_03_How it works

## Verify the fix

1. 1

### Reproduce on the same URL

Request the exact URL that failed with `curl -sSI` and confirm a 2xx or the intended status, not 502.
2. 2

### Watch the error log while you test

Run `tail -f` on the error log and repeat the request. A fixed backend stops adding lines for that request.
3. 3

### Test again after a backend restart

Restart the backend and request the page. If a 502 appears only right after a restart, a pooled connection or the worker error state is a likely cause; check `ttl` and `retry`.

If Apache sits behind a CDN or load balancer, test the origin hostname and the public hostname separately, because the CDN can show its own 502 while Apache is healthy. Google treats 5xx responses as server errors, so see [5xx server errors](/seo-issues/server-errors-5xx) for the crawl impact.

Sources · 6

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- rfc-editor.org
- apache.org
- php.net
- google.com

1. 01 [RFC 9110: HTTP Semantics](https://www.rfc-editor.org/rfc/rfc9110.html) rfc-editor.org · checked 2026-10-25
2. 02 [Apache HTTP Server 2.4: mod_proxy](https://httpd.apache.org/docs/2.4/mod/mod_proxy.html) httpd.apache.org · checked 2026-10-25
3. 03 [Apache HTTP Server 2.4: mod_proxy_fcgi](https://httpd.apache.org/docs/2.4/mod/mod_proxy_fcgi.html) httpd.apache.org · checked 2026-10-25
4. 04 [Apache HTTP Server 2.4: core features (ErrorLog, LogLevel)](https://httpd.apache.org/docs/2.4/mod/core.html) httpd.apache.org · checked 2026-10-25
5. 05 [PHP manual: FPM configuration](https://www.php.net/manual/en/install.fpm.configuration.php) php.net · checked 2026-10-25
6. 06 [How HTTP status codes affect Google's crawlers](https://developers.google.com/crawling/docs/troubleshooting/http-status-codes) developers.google.com · checked 2026-10-25

Questions

## Asked a lot.

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

_01_ How do I fix 502 Bad Gateway in Apache?

Read the Apache error log for the failing request, test the backend directly with curl, then check the `ProxyPass` or `SetHandler` target, whether the backend is running, and the `retry`, `ttl` and `disablereuse` settings. Run `apachectl configtest` before reloading.

_02_ Is a 502 error permanent?

No. RFC 9110 defines it as an invalid response from an inbound server, which usually clears once the backend or the proxy settings are fixed. In Apache, a worker in the error state can keep failing until its `retry` time ends.

_03_ What does bad gateway mean on a website?

The server you reached acted as a gateway and the server behind it did not give a valid answer. In Apache the gateway is mod_proxy or mod_proxy_fcgi and the server behind it is your app or PHP-FPM.

_04_ Does a bigger ProxyTimeout stop 502 errors?

Usually not. The timeout is how long Apache waits for data from the backend. A 502 points to an invalid or refused response, so look at what the backend returned and at the proxy worker settings.

## Keep learning

[All errors](/errors)

[Learn 502 Bad Gateway HTTP status codes](/errors/http/502) [Related 404 Not Found on Apache HTTP status codes](/errors/http/404/apache) [Read next 502 Bad Gateway in nginx HTTP status codes](/errors/http/502/nginx) [Do Run a free site audit Free, about two minutes](/site-audit)

Other 502 errors
[Google Cloud 502 Bad Gateway](/errors/cdn/google-cloud-502) [Render 502 Bad Gateway](/errors/cdn/render-502) [502 Bad Gateway](/errors/http/502) [502 Bad Gateway in nginx](/errors/http/502/nginx) [502 Bad Gateway on Azure](/errors/http/502/azure)

Nearby in errors
[HTTP 501 Not Implemented](/errors/http/501)

More in 502 Bad Gateway
[502 Bad Gateway in Apache](/errors/http/502/apache) [502 Bad Gateway in nginx](/errors/http/502/nginx) [502 Bad Gateway on Azure](/errors/http/502/azure) [502 Bad Gateway on Cloudflare](/errors/http/502/cloudflare)

Terms on this page
[Inbound marketing](/glossary/inbound-marketing)

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
