Free auditStart free
GuideError · HTTP status codes

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.

4 min
read
6
sources
Oct 25, 2026
updated
Scaplet Editorial Team
author
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
  2. Causes specific to Apache and where to fix them
  3. 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 withChatGPTClaudePerplexityGoogleAI Mode
01Check 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 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. This page covers what is specific to Apache. If you run nginx instead, use 502 Bad Gateway in 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
02Apache 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>
03How 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 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. 01RFC 9110: HTTP Semanticsrfc-editor.org · checked 2026-10-25
  2. 02Apache HTTP Server 2.4: mod_proxyhttpd.apache.org · checked 2026-10-25
  3. 03Apache HTTP Server 2.4: mod_proxy_fcgihttpd.apache.org · checked 2026-10-25
  4. 04Apache HTTP Server 2.4: core features (ErrorLog, LogLevel)httpd.apache.org · checked 2026-10-25
  5. 05PHP manual: FPM configurationphp.net · checked 2026-10-25
  6. 06How HTTP status codes affect Google's crawlersdevelopers.google.com · checked 2026-10-25
Questions

Asked a lot.

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

01How 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.

02Is 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.

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

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

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