Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Azure App Service on Linux restarts the container and the site never starts

ErrorGET /robots933456.txt HTTP/1.1 404 in the container log (this means the container is healthy)

Short answer

App Service sends a warmup request to the container and restarts it if no HTTP answer comes back in time. The usual reasons are the wrong port, an app that never starts listening, a slow start, or a start command that does not keep a process in the foreground. Turn on container logs first.

  • Applies to Azure App Service Linux, Node.js 22, PM2 5, Azure CLI 2.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Turn on container logging and read the log stream. It shows whether the app crashed, never listened, or listened on another port.

    az webapp log config --name <app-name> --resource-group <group> --docker-container-logging filesystem
    az webapp log tail --name <app-name> --resource-group <group>
  2. 2Match what you see, then jump to its fix

    1. 1The app listens on a port other than 80 or 8080, and warmup failsA custom container listens on a port App Service does not knowFix
    2. 2Node.js runtime stack, app hard-codes a portA built-in Node.js image app ignores the PORT variableFix
    3. 3The log shows the app still starting when the container is restartedThe container needs longer than the warmup windowFix
    4. 4No reply at all to GET /robots933456.txtThe app does not answer the warmup pathFix
    5. 5Custom Docker image with CMD or a startup command of pm2 startA custom image runs the app through plain PM2 instead of pm2-runtimeFix

What does the error look like?

  • GET /robots933456.txt HTTP/1.1 404 in the container log (this means the container is healthy)
  • The container restarts again and again and the site returns an application error

Cause 1 of 5

A custom container listens on a port App Service does not know

1Check

For a custom container App Service detects port 80 or 8080 by itself. Any other port needs the WEBSITES_PORT app setting, with a matching EXPOSE in the Dockerfile. Only one port is supported.

az webapp config appsettings list --name <app-name> --resource-group <group>

2Fix

Set WEBSITES_PORT to the port your app binds to.

az webapp config appsettings set --resource-group <group> --name <app-name> --settings WEBSITES_PORT=3000

3Verify

The log stream shows the warmup request answered and the site responds.

curl -I https://<app-name>.azurewebsites.net

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 5

A built-in Node.js image app ignores the PORT variable

1Check

For built-in containers the platform tells your code which port to use through the PORT environment variable.

grep -n "listen" server.js

2Fix

Read PORT in the app, with a fallback for local runs.

const port = process.env.PORT || 3000;
app.listen(port);

3Verify

Redeploy and watch the log stream until the app answers.

az webapp log tail --name <app-name> --resource-group <group>

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 5

The container needs longer than the warmup window

1Check

The warmup request waits a fixed time for a reply. If the app takes longer to start than that window, the container is restarted before it is ready.

az webapp config appsettings list --name <app-name> --resource-group <group>

2Fix

Raise WEBSITES_CONTAINER_START_TIME_LIMIT. The documented range is up to 1800 seconds.

az webapp config appsettings set --resource-group <group> --name <app-name> --settings WEBSITES_CONTAINER_START_TIME_LIMIT=600

3Verify

The log stream shows the app start and answer the warmup request.

az webapp log tail --name <app-name> --resource-group <group>

Confirmed by learn.microsoft.com

Did this fix it?

Cause 4 of 5

The app does not answer the warmup path

1Check

The warmup request goes to a dummy path, /robots933456.txt, and any status code is enough, even 404 or 5xx. If your app logic never replies to unknown paths, the warmup gets no answer and the container is restarted over and over.

curl -i http://127.0.0.1:<port>/robots933456.txt

2Fix

Make unknown routes return a normal HTTP response, or set WEBSITE_WARMUP_PATH to a route you serve and WEBSITE_WARMUP_STATUSES to the codes that count as ready.

az webapp config appsettings set --resource-group <group> --name <app-name> --settings WEBSITE_WARMUP_PATH=/health

3Verify

The log shows the warmup path answered.

az webapp log tail --name <app-name> --resource-group <group>

Confirmed by learn.microsoft.com

Did this fix it?

Cause 5 of 5

A custom image runs the app through plain PM2 instead of pm2-runtime

1Check

PM2's own Docker guide says to run pm2-runtime as the container command instead of the plain node or pm2 start.

grep -n "CMD\|ENTRYPOINT" Dockerfile

2Fix

Switch the command to pm2-runtime.

# Dockerfile
CMD ["pm2-runtime", "ecosystem.config.js"]

3Verify

Rebuild, push the image and watch the log stream until the app answers.

az webapp log tail --name <app-name> --resource-group <group>

Confirmed by pm2.keymetrics.io

Did this fix it?

How do I stop it coming back?

  • Add a lightweight /health route and set WEBSITE_WARMUP_PATH to it.
  • Keep one port in the Dockerfile, in WEBSITES_PORT and in the code.
  • Do slow work such as migrations after the server starts listening, not before.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

The SSH@0 task cannot log in to the remote machine

All configured authentication methods failed

The SSH task logs in with the details stored in its SSH service connection, so the failure is almost always in that connection or on the server.

4 causes, each with a fix

Servers

nginx gives up waiting for the app and returns 504

upstream timed out (110: Connection timed out) while reading response header from upstream

nginx returns 504 when the app behind it takes the request but sends nothing back within proxy_read_timeout (60 seconds by default), or when the connection cannot be opened in time.

5 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.