You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure上Node.js站点无法加载,重新发布后日志出现异常

Troubleshooting "Service Unavailable" for Your Express.js App on Azure

Hey there, let's work through this issue—your Express app was running smoothly since March, but now it's throwing "Service Unavailable" after redeployment, and the logstream only shows partial deployment steps. Here are actionable steps to diagnose and fix this:

  • First, confirm the deployment finished successfully
    The logs you shared cut off at "Preparing deployment for commit id '7579046ef...", which means we don't know if the deployment completed without errors. Head to the Azure Portal's Deployment Center for your app, find the latest deployment, and check the full log. Look for red flags like failed npm install commands, missing dependencies, or a broken build script in your package.json—any of these can halt deployment and leave your app in an unstartable state.

  • Double-check your app's startup configuration
    Azure needs explicit instructions to launch your Express app. Make sure your package.json has a valid start script, e.g.:

    "scripts": {
      "start": "node server.js"
    }
    

    Replace server.js with your actual entry file. If you use a custom startup command, verify it's still correct in the Azure Portal under Configuration > General settings > Startup Command. Redeployments sometimes reset this setting, especially if you changed your entry file recently.

  • Ensure your app listens on the correct port
    Azure doesn't use the default 3000 port—it assigns a dynamic port via the PORT environment variable. If your code hardcodes port 3000, Azure can't route traffic to your app. Update your Express startup code to use:

    const port = process.env.PORT || 3000;
    app.listen(port, () => {
      console.log(`Server running on port ${port}`);
    });
    

    The fallback to 3000 lets you test locally, while process.env.PORT ensures compatibility with Azure.

  • Pull full runtime logs to catch app startup errors
    The logstream you checked only shows deployment logs. To see why your app isn't starting, enable Application Logging (Filesystem) in the Azure Portal under App Service > Logs, then restart your app. You can also use the Azure CLI command az webapp log tail --name <your-app-name> --resource-group <your-resource-group> to get real-time runtime logs. This will reveal issues like missing modules, syntax errors, or failed database connections that the deployment logs don't show.

  • Check for resource limits
    It's possible your App Service plan is hitting CPU or memory limits. Head to App Service > Metrics and monitor CPU, Memory, and Disk usage over the last few hours. If resources are maxed out, try scaling up your plan to a higher tier (e.g., from Free to Basic) or scaling out to add more instances. Also, check for unexpected background processes eating up resources.

  • Roll back to a known working deployment
    Since your app ran fine until today, roll back to a deployment from before the issue started. In the Azure Portal's Deployment Center > Deployments, select a successful deployment from March or early April, then click Rollback. This will revert your app to a stable state, helping you figure out if the problem comes from recent code changes or an Azure environment issue.

内容的提问来源于stack exchange,提问作者balexandre

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:53:22