我尝试将我的 NestJs 应用程序(使用快速适配器)部署到 Azure 应用服务。在 docker 日志中我收到此错误:
2020-11-20T10:42:02.911Z INFO - docker run -d -p 8947:8080 --name xxx_0_37a36398 -e WEBSITES_PORT=8080 -e WEBSITE_SITE_NAME=xxx -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=xxx.azurewebsites.net -e WEBSITE_INSTANCE_ID=xxx appsvc/node:14-lts_20200918.1 yarn start:prod
2020-11-20T10:42:02.912Z INFO - Logging is not enabled for this container.
Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2020-11-20T10:42:05.088Z INFO - Initiating warmup request to container xxx_0_37a36398 for site xxx
2020-11-20T10:42:20.586Z INFO - Waiting for response to warmup request for container xxx_0_37a36398. Elapsed time = 15.4982001 sec
2020-11-20T10:48:35.794Z INFO - Waiting for response to warmup request for container xxx_0_37a36398. Elapsed time = 390.7060158 sec
2020-11-20T10:56:21.027Z INFO - Waiting for response to warmup request for container xxx_0_37a36398. Elapsed time = 855.9388558 sec
2020-11-20T11:04:08.996Z INFO - Waiting for response to warmup request for container xxx_0_37a36398. Elapsed time = 1323.907606 sec
2020-11-20T11:11:55.596Z INFO - Waiting for response to warmup request for container xxx_0_37a36398. Elapsed time = 1790.5073044 sec
2020-11-20T11:12:25.625Z ERROR - Container xxx_i_0_37a36398 for site xxx did not start within expected time limit. Elapsed time = 1820.5363685 sec
2020-11-20T11:12:25.627Z ERROR - Container xxx_0_37a36398 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2020-11-20T11:12:25.637Z INFO - Stopping site xxx because it failed during startup.
应用程序日志显示应用程序启动成功
2020-11-20T10:42:05.150205868Z _____
2020-11-20T10:42:05.150227670Z / _ \ __________ _________ ____
2020-11-20T10:42:05.150232970Z / /_\ \___ / | \_ __ \_/ __ \
2020-11-20T10:42:05.150237271Z / | \/ /| | /| | \/\ ___/
2020-11-20T10:42:05.150241271Z \____|__ /_____ \____/ |__| \___ >
2020-11-20T10:42:05.150245371Z \/ \/ \/
2020-11-20T10:42:05.150249272Z A P P S E R V I C E O N L I N U X
2020-11-20T10:42:05.150252972Z
2020-11-20T10:42:05.150256472Z Documentation: http://aka.ms/webapp-linux
2020-11-20T10:42:05.150260173Z NodeJS quickstart: https://aka.ms/node-qs
2020-11-20T10:42:05.150263673Z NodeJS Version : v14.7.0
2020-11-20T10:42:05.150267273Z Note: Any data outside '/home' is not persisted
2020-11-20T10:42:05.150270874Z
2020-11-20T10:42:05.388794060Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2020-11-20T10:42:05.389362508Z Could not find operation ID in manifest. Generating an operation id...
2020-11-20T10:42:05.389393011Z Build Operation ID: 5488a73a-f6e1-48d5-9360-7d4e0db141f4
2020-11-20T10:42:06.033354810Z Environment Variables for Application Insight's Codeless Configuration exists..
2020-11-20T10:42:06.603097828Z Writing output script to '/opt/startup/startup.sh'
2020-11-20T10:42:06.946048753Z Running #!/bin/sh
2020-11-20T10:42:06.946644503Z
2020-11-20T10:42:06.946657204Z # Enter the source directory to make sure the script runs where the user expects
2020-11-20T10:42:06.946662305Z cd "/home/site/wwwroot"
2020-11-20T10:42:06.946666105Z
2020-11-20T10:42:06.947939813Z export NODE_PATH=/usr/local/lib/node_modules:$NODE_PATH
2020-11-20T10:42:06.947952014Z if [ -z "$PORT" ]; then
2020-11-20T10:42:06.947956114Z export PORT=8080
2020-11-20T10:42:06.949015304Z fi
2020-11-20T10:42:06.954862399Z
2020-11-20T10:42:06.954927704Z export NODE_OPTIONS='--require /usr/local/lib/node_modules/applicationinsights/out/Bootstrap/Oryx.js ' $NODE_OPTIONS
2020-11-20T10:42:06.954986409Z PATH="$PATH:/home/site/wwwroot" yarn start:prod
2020-11-20T10:42:08.321443397Z yarn run v1.17.3
2020-11-20T10:42:08.484387733Z $ node dist/src/main
[...]
2020-11-20T10:42:23.394152218Z Application started on port 8080
我用这一行绑定(bind)了express服务器
const port = Number(process.env.PORT) || 8080;
我用谷歌搜索了一段时间来寻找解决方案,但没有任何帮助。以下是我现在尝试使用的步骤。
- 将
WEBSITES_CONTAINER_START_TIME_LIMIT
增加到 1800 - 将
WEBSITES_PORT
和PORT
设置为 80 - 重新创建并重新部署应用
有人知道为什么这个问题仍然出现吗?我的应用程序列在正确的端口上,并在 /
下返回 200 Http 状态,并且还实现了 400 错误处理程序(我了解到此云也是一个问题)。
最佳答案
你可能使用Sentry吗?我们遇到了类似的问题,并且能够将其追溯到 Sentry。在没有 Sentry 和默认配置的情况下尝试一下。
关于node.js - 将 Express 应用程序部署到 Azure 应用程序服务未响应端口 : 8080 上的 HTTP ping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64928674/