What an App Service 502 error means
HTTP 502 indicates that a gateway or front-end component could not obtain a valid response from the application worker or an upstream dependency. The visible status code does not identify the root cause. Common causes include application startup failures, incorrect container ports, unhealthy workers, deployment errors, dependency timeouts, and proxy or routing problems.
Start by defining the failure boundary. Confirm whether the default App Service hostname fails, whether every instance is affected, when the problem began, and whether it followed a deployment or configuration change. This prevents an application failure from being mistaken for an Application Gateway, Front Door, DNS, or network problem.
Evidence to collect before changing production
Collect deployment logs, application logs, container logs, platform diagnostics, health-check state, Application Insights exceptions, and a timestamped reproduction. Compare configuration and application settings with the last known working state. For custom containers, verify that the process remains running and listens on the expected port.
A successful deployment record does not prove that the application started successfully. Deployment and runtime are separate stages. Look for process exits, missing environment variables, module-loading failures, certificate problems, connection failures, and startup timeouts.
- Test the default azurewebsites.net hostname to isolate upstream routing.
- Check deployment and restart timestamps against the first 502 response.
- Review startup commands, stack versions, container ports, and health checks.
- Use a deployment slot or rollback plan before applying a production change.
Recovering safely from repeated 502 responses
Prefer the smallest reversible action that tests the leading hypothesis. Restarting can restore service temporarily, but it may also remove evidence and conceal a recurring startup problem. Capture logs first whenever the incident allows it.
After recovery, verify more than the HTTP status. Check representative application transactions, dependency calls, instance health, error rates, latency, and monitoring. Record the cause and preventive action so the same deployment or configuration failure is detected earlier next time.
Frequently asked questions
Why does App Service return 502 immediately after deployment?
The new application may be failing during startup, listening on the wrong port, missing configuration, or exceeding a startup timeout. Deployment logs and runtime logs must be checked separately.
Should I restart the App Service first?
A restart can help, but collect available logs and configuration evidence first. Otherwise the restart may remove useful evidence without resolving the underlying problem.
Can an upstream gateway cause the 502?
Yes. Test the default App Service hostname and compare it with Application Gateway, Front Door, or custom-domain behavior to identify the failing boundary.