NGINX 502 After an Update? Trace the Connection to PHP

Illustrated infographic summarizing: NGINX 502 After an Update? Trace the Connection to PHP

By Greg Nowak. Updated 23 November 2026.

A 502 Bad Gateway after maintenance can leave customers unable to submit an enquiry or finish checkout. The immediate priority is restoring that journey. The next is understanding why it failed, so another restart does not bring the problem back.

For websites where NGINX forwards PHP requests to PHP-FPM, start by tracing that connection. Which backend did NGINX try to reach? Was it listening? Could NGINX access it? The error page alone cannot answer those questions, but the configuration and matching logs usually give you a useful starting point.

Capture the failure before changing settings

Record an affected URL, the request time and the corresponding NGINX error entry. Note whether the failure affects every PHP request, one website or a particular action. Save relevant logs and configuration before further changes obscure the evidence.

Choose a repeatable request that actually exercises PHP. A cached homepage or static image may load while the application remains unavailable. For checkout and forms, agree a safe test that avoids duplicate orders or messages.

If the outage is continuing, assess a known recovery option or rollback with the responsible team. Keep a record of what restores service; recovery and a confirmed diagnosis are separate milestones.

Compare the NGINX destination with the PHP-FPM listener

Start by inspecting the configuration files NGINX would load:

sudo nginx -T

The NGINX command documentation explains that -T tests and prints the configuration. Use the same binary, configuration path and runtime environment as the service. This reads files on disk; it does not prove that running workers have loaded recent edits. Keep the output private because configuration can contain sensitive values.

Find the server and location handling the failed request, then follow fastcgi_pass, including any upstream group. The FastCGI documentation supports TCP destinations and Unix sockets, for example:

fastcgi_pass 127.0.0.1:9000;
# Alternative Unix-socket destination:
fastcgi_pass unix:/run/php/site.sock;

These are alternatives, not settings to paste in together. Compare the actual destination with listen in the intended PHP-FPM pool. After a PHP upgrade, check for a versioned socket path or service change, but establish the mismatch before editing anything.

Let the error choose the next check

Read the complete log entry, including the upstream address and the stage of the request. Use these clues to direct the investigation; none establishes the cause on its own.

NGINX-to-PHP troubleshooting: match the symptom to the next check.
Log clue Check next Evidence before closing
No such file or directory while connecting Configured socket path, intended pool and startup logs The expected socket is recreated and PHP requests succeed
Permission denied while connecting Worker identity, socket permissions, parent directories and security policy NGINX can connect after PHP-FPM recreates the socket
Connection refused Actual listener, address, port and service health The intended pool accepts requests at that endpoint
Prematurely closed connection or invalid header PHP-FPM and application logs, worker exits and response handling The same action completes with a valid response
Timeout Failed stage, queueing, slow application work and dependencies Repeated requests complete within an agreed time

Make socket permission fixes survive recreation

A manual permission change can appear to solve the outage until PHP-FPM creates the socket again. Check the pool settings that create it, alongside directory access and the NGINX worker identity.

The PHP-FPM configuration reference documents listen.owner, listen.group and listen.mode. It also identifies an easily missed detail: when socket ACL settings are used, listen.owner and listen.group are ignored. Check which mechanism applies before changing ownership.

Avoid using world-writable permissions as the fix. If ordinary permissions look correct, investigate applicable SELinux or AppArmor denials. For TCP connections, check from NGINX's runtime environment: in containers, its localhost may refer to a different container from PHP-FPM.

If PHP is reachable, check capacity and application behaviour

A listening endpoint does not establish that PHP can complete the affected request. Compare PHP-FPM and application logs with the same timestamp.

If a restricted status endpoint exists, the PHP-FPM status page exposes the pool name, start time, listen queue and process counts. Confirm that you are observing the right pool. Its max children reached value records whether the limit has been reached since startup; it does not prove current saturation. Watch observations across the failing test.

Keep status access internal or limited to known IPs because it exposes request and resource information. If requests queue, investigate slow work and available memory before increasing pm.max_children.

Likewise, justify timeout changes with evidence. NGINX's fastcgi_read_timeout measures inactivity between successive reads, rather than a total request deadline. Raising it will not repair a missing socket or a worker that exits unexpectedly.

Use debug logging for a specific unanswered question

When normal logs leave the connection sequence unclear, use nginx -V to check for debug support. The NGINX debugging guide explains debug logging and selecting client addresses with debug_connection. More specific log declarations can also disable inherited debugging if they omit the debug level.

Capture a controlled reproduction, protect the diagnostic output and remove temporary logging afterwards.

Close the incident with a business test and a handover

Test configuration changes with sudo nginx -t before reloading through your normal service procedure. Then repeat the original action and inspect fresh logs. A successful syntax check does not test the PHP connection.

Arrange a controlled PHP-FPM restart to verify listener recreation and recovery. If a reboot triggered the incident, include that test in a suitable maintenance window. Confirm the enquiry arrives or the agreed checkout test completes.

The handover should state the cause, supporting evidence, changed settings, test results and the check to add to future maintenance.

If your team needs help tracing the failure or coordinating hosting and application work, contact Greg. A focused investigation can establish what needs correcting and give the owner and agency clear acceptance criteria.

Related on GrN.dk

Need help with this kind of work?

Discuss your NGINX and PHP issue with Greg Get in touch with Greg.

Sources

Latest articles

Let’s Encrypt moves to 64-day certificates on 10 February 2027. Check when each site renews, test the reload and verify the certificate visitors receive.

Work out which Drupal 10 sites can move to Drupal 11 by 9 December, who can resolve each blocker and how to test publishing and rollback before launch.

See how SharePoint access changes reach internal AI search, and test how long revoked content can still appear in results, generated answers, and citations.

At month-end, reconcile Shopify Payments against your bank statement and e-conomic. Use the payout ID to trace fees, refunds, and payouts that reach your bank the following month.

Trace an intermittent NGINX 502 through Cloudflare, upstream attempts, and application logs so you can see where the request failed and who should pick it up.

Find the apps, scripts and printers that still send mail through Microsoft 365 with a mailbox password, then test a replacement before the December 2026 change.

Find subscriptions and insurance expenses in e-conomic that should be spread over several months. See how AI reads the supporting documents and how your finance lead approves the proposed allocations.

Before relying on an AI project briefing, check which files it covered. A practical workflow for tracking documents, recording gaps and verifying key claims.

Check whether your contact form rejects missing or invalid Turnstile tokens, handles failed checks for genuine users and delivers accepted enquiries to your team.

Compare Bing citations, identifiable AI visits and verified enquiries to see which pages deserve attention before you increase your AI search marketing budget.