Trace the request through the gateway that answered
A shopper opening a product page may connect to a Cloudflare edge, which contacts Nginx, which hands the request to PHP-FPM. A Node service behind Caddy replaces the last hop with an HTTP connection to the application. Draw the actual path for the affected URL using the deployed routing configuration. The same domain can deliver product photos from object storage, an article from an edge cache and the checkout from an entirely different pool. A working photograph establishes very little about the payment route.
If the report concerns a purchase, treat the transaction separately from the failed response. The application may have accepted the order before the connection back to the proxy broke. Look up the order and payment reference through your normal merchant interface. Replaying a purchase request can produce a duplicate charge or a second shipment. Choose an ordinary read-only page on the same application for subsequent checks, and keep authorization headers, session cookies and customer information out of shared incident notes.
| Status | What the sender is reporting | First evidence to collect |
|---|---|---|
| 502 Bad Gateway | The next service failed to supply a usable response | Upstream address and connection error in the gateway log |
| 503 Service Unavailable | The service is temporarily unable to handle the request | Instance readiness, capacity and maintenance events |
| 504 Gateway Timeout | The next service failed to respond in time | Wait stage, elapsed time and application queue |
Save the exact time with its time zone and any edge request identifier. A branded error page can tell you a CDN handled the response. Look for the corresponding request at the origin to determine which component first produced an error. If the customer saw an access refusal instead, the investigation starts with permissions and policies in the 403 troubleshooting guide. Cloudflare’s origin and edge troubleshooting guidance.
Compare the public response with the application route
Set the shell variable URL to the full affected address. The first command below sends HEAD and displays connection details. The second sends GET and stores the headers and body separately so you can inspect what a visitor actually receives. Use a private working directory because headers can contain session data. Keep the first redirect visible and then inspect its destination separately. Following an entire redirect chain in silence can make the healthy first hop look like the component that failed.
date -u
curl -svI "$URL"
curl -sS -D response.headers -o response.body -w '%{http_code} %{time_starttransfer} %{time_total}\n' "$URL"
Compare an affected dynamic page with a known public asset on the same host. Record whether each came from an edge cache, its age if available, and the first byte timing. A nearly immediate refusal suggests a different investigation from a long wait followed by a broken response. Timing alone cannot name the failed component. The guide to measuring high TTFB explains how to distinguish cached delivery from application work when comparing samples.
Account for recent hosting changes
After a migration, a load balancer may still send a share of traffic to an old instance. Compare failed upstream addresses with the current pool membership and deployment inventory. On a host you administer, confirm that the virtual host name, enabled PHP service and socket path belong to the same release. Use the WordPress hosting migration checklist to review the cutover. Preserve the hostname and TLS verification when previewing the new server so you exercise the right virtual host.
Read the proxy and application logs side by side
Start with the origin access log filtered to the reported minute and path. Then inspect the proxy error log and the application service for that exact interval. If your access log already records upstream address, status and timing, retain them together. A proxy can try more than one backend before returning a response. A healthy response from the last attempt can coexist with a connection failure on the first instance. Sorting by address and time reveals a single bad node that an overall success rate can hide.
journalctl -u nginx --since '15 minutes ago' --no-pager
journalctl -u caddy --since '15 minutes ago' --no-pager
ss -ltn
ss -lx
Use the commands that match your installation. Nginx often writes request errors to a file selected by its error_log directive. Caddy managed by systemd commonly sends service output to the journal. Find the pool serving the affected host before reading php-fpm.log or the relevant unit journal. A container may send messages to its standard error stream instead. A silent log for an unused PHP version proves little about the pool that actually received the request.
| Proxy evidence | Question to answer | Change supported by the observation |
|---|---|---|
| Connection refused | Is the application listening at the configured address? | Restore a healthy process or correct the upstream port |
| No such file on a socket connection | Did the active pool create the expected socket? | Align the configured socket paths and retest |
| Upstream closed the connection early | Which process exited before sending complete headers? | Repair the failure recorded at the same time |
| Upstream sent too big header | Which response headers grew on that route? | Reduce excess headers or size the first buffer to the measured need |
For a Unix socket, distinguish a missing file from denied access to an existing file. Check the owner, group and directory traversal permissions used by the web server. If the socket disappears whenever PHP updates, its configured path or the active pool may have changed. Correct ownership and mode in the pool configuration so they survive a restart. Making the socket accessible to every local account can obscure the initial diagnosis and grant unintended access to the application.
Investigate busy workers, process exits and memory pressure
A PHP-FPM pool can handle only as many simultaneous requests as its configured worker ceiling permits. A worker waiting for a database lock or a shipping quote can occupy a slot while consuming almost no CPU. Compare queue length, active workers, slow requests and arrival rate during the same incident window. A warning about pm.max_children establishes that the pool reached its ceiling. Find out what the workers were doing before you increase their number. PHP-FPM pool settings.
A stock import and a checkout might share the same database even when their application workers are separate. If the incident repeats at an exact time each morning, compare it with import schedules, backup jobs and changes in database lock waits. A slow request trace can show whether a worker spends its time waiting for that database or for a remote HTTP call. Collect traces for a limited interval and store them outside the public web directory because arguments and paths can contain business data.
If workers vanish abruptly, inspect kernel events and the memory limit assigned to the service. A container may prevent access to the host kernel log, in which case use the platform event history or ask the host operator for the matching timestamp. Exit code 137 indicates a process killed by SIGKILL. Confirm an out-of-memory event from the kernel or container runtime before attributing that exit to the OOM killer.
dmesg -T | grep -Ei 'out of memory|oom-kill|killed process'
journalctl -k --since '30 minutes ago' --no-pager
Estimate memory use with representative traffic and reserve space for the operating system, database and temporary spikes. Summing resident size across workers can count shared memory more than once, so compare the estimate with actual service or container consumption. Increasing both worker count and the per-request PHP memory allowance can make an outage more frequent. If PHP returns a complete application-level error page, follow the WordPress white screen recovery steps to investigate the underlying fatal error.
Choose the right timeout or response buffer
Read the route configuration to identify the transport. Nginx settings prefixed with proxy apply to HTTP proxying, while a PHP-FPM connection using FastCGI has its own family of directives. With Caddy, review the transport of the matching reverse proxy route. A syntax check can pass while a change has no effect on the affected path because the edited block serves a different application. Record the active value and save a reversible configuration change before testing the fix.
Connection establishment and reading an established stream have separate deadlines. The Nginx proxy read timeout measures the gap between successive reads, so a steadily streaming response may run longer than that total duration. If requests stall before headers arrive, ask whether work started and what dependency the worker is waiting for. A long-running export can often be moved to a background job that gives the user a job identifier and a download link once the export finishes.
If only signed-in customers see the problem, compare response header sizes for a clean session and the failing route. Multiple extensions may append cookies on every navigation or refresh a large session payload. The Nginx proxy_buffer_size directive sizes the initial buffer used to read the HTTP upstream response, including its headers. For a FastCGI route examine fastcgi_buffer_size. Correct duplicate or excessive headers first. If a larger buffer is justified, exercise both authenticated and anonymous pages under representative load. Nginx HTTP proxy directive reference.
Restore traffic and prove the repair held
If failures began with a release, a previous application image may still be healthy and compatible with the current database. Save the failing instance logs, release identifier and routing evidence before replacement. Verify backwards compatibility if the new service already wrote records in a changed format. Rolling back application code and restoring a database snapshot have different effects on payments and orders recorded since deployment. Make the smallest change that restores the affected operation while preserving those writes.
Pros and cons
Repeat the original read-only request through the public hostname. Confirm the expected title, a meaningful element in the body, and the status. If the affected route requires a signed-in session, verify it with an authorized account as well. Match those successful requests to fresh logs from the upstream and proxy. Observe the next relevant peak or scheduled job that previously triggered the failure. Record both the outage interval and the precise signal you used to decide it was safe to restore normal traffic.
Check crawling after repeated gateway failures
Repeated server errors can cause Google to reduce its crawl rate. A URL that remains unavailable may eventually drop from the index. A single failed request does not determine a ranking change or provide a reliable recovery deadline. Establish which page groups were affected and check whether robots.txt and the sitemap were accessible during the same interval. A cached home page can be healthy while a crawler receives errors on every product detail page. Google’s documentation on HTTP errors.
Use Search Console URL Inspection on a small selection from each affected template and compare the results with actual origin traffic. A live inspection tells you about that particular request today. Crawl statistics describe prior requests and can lag behind the repair. Keep permanent page addresses intact during a temporary outage. Redirecting all product pages to the home page or serving an error template with a success status hands crawlers the wrong document and makes monitoring less informative.
Frequently asked questions
What should a visitor do after a 502?
Record the time and page address, wait briefly and reload a read-only page. If you had just submitted a payment, check the confirmation and contact the merchant before trying to place the order again.
Why is the home page working while my account fails?
The home page may be served from a cache while the account route needs the application, a database and the session store. Find the account request in the logs and identify the backend used for that route.
Will restarting Nginx fix a bad gateway?
A restart may briefly change the symptoms of a proxy process problem. Preserve the error details and check the next hop first, since restarting the gateway cannot recreate a missing PHP socket.
Why does the error page mention Cloudflare?
Cloudflare handled the public request and may have relayed an error received from your origin. Save the request identifier and time, then compare your origin response with the edge record for that request.
Should I purge every cached page after recovery?
Check the affected URL first for evidence that an error was actually cached. A full purge can send many simultaneous misses to a recovering application, so invalidate only the confirmed entries and verify the next response.
Need help with your website?
Development and SEO services →