简体   繁体   English

Azure 应用程序服务中的 Nodejs 应用程序始终返回 HTTP 错误 404

[英]Nodejs app in Azure app service always returns HTTP ERROR 404

I am trying to learn azure app services deploying a very basic nodejs "hello world" applicatio.我正在尝试学习部署一个非常基本的 nodejs“hello world”应用程序的 azure 应用程序服务。 I deploy successfully the app from Azure Devops server release pipeline, I can see the app in azure portal in started state but when I try to access it I get我从 Azure Devops 服务器发布管道成功部署了该应用程序,我可以在 azure 门户中看到该应用程序已启动 state 但是当我尝试访问它时我得到

This sieracnodejasdemo.azurewebsites.net page can't be found HTTP ERROR 404. whereas app is up and running找不到此 sieracnodejasdemo.azurewebsites.net 页面 HTTP 错误 404。而应用程序已启动并正在运行

在此处输入图像描述

Here is the basic index.js这是基本的 index.js

var http = require('http');
var server = http.createServer(function(request, res) {


    res.writeHead(200, { "Content-Type": "text/plain" });
    var url = request.url;

    if (url === '/about') {
        res.write(' Welcome to about us page');
        res.end();
    } else if (url === '/contact') {
        res.write(' Welcome to contact us page');
        res.end();
    } else {
        res.write('Hello World!');
        res.end();
    }
});


const port = process.env.PORT || 3000;
console.log(port);
server.listen(port);
console.log("Server running at http://%d", port);

It seems to me that it is a problem of PORT, so 1st question should I add a firewall rule for the port?在我看来这是端口的问题,所以第一个问题我应该为端口添加防火墙规则吗? I even replaced process.env.PORT by 80 but id did not help, always the same error.我什至用 80 替换了 process.env.PORT 但 id 没有帮助,总是同样的错误。 I tried to change the node version to ~10 or 18 in settings but did not help neither.我试图在设置中将节点版本更改为 ~10 或 18,但都没有帮助。 So what am I missing to make it respond correctly?那么我缺少什么才能使其正确响应? Knowing that when I run it on my local machine it works fine Thanks for your help知道当我在本地机器上运行它时它工作正常谢谢你的帮助

I have tried to repro the same in my environment and am able to deploy the nodeJS application successfully after following the below steps .我尝试在我的环境中重现相同的内容,并且能够在执行以下步骤后成功部署 nodeJS 应用程序

Step 1: Created a Sample nodeJS application in VS code and pushed it to Azure Repos.第 1 步:在 VS 代码中创建一个示例 nodeJS 应用程序并将其推送到 Azure Repos。

Step 2: Create build steps as below.第 2 步:创建构建步骤如下。 在此处输入图像描述在此处输入图像描述在此处输入图像描述在此处输入图像描述在此处输入图像描述

Step 3: Run the pipeline and verify the artefact generated.第 3 步:运行管道并验证生成的工件。

Step 4: Create an Azure App service with Runtime ' Node 18 LTS' and Operating system Linux第 4 步:使用运行时“ Node 18 LTS”和操作系统Linux创建一个 Azure 应用服务

Step5: Create a Service connection in Azure DevOps Step5:在Azure DevOps中创建Service连接

Step 6: Create a Release pipeline as below.第 6 步:创建一个发布管道,如下所示。 在此处输入图像描述在此处输入图像描述在此处输入图像描述在此处输入图像描述

Step 7: Once deployment is completed, verify the app service.第 7 步:部署完成后,验证应用服务。在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure 应用程序服务上的守护进程 OWASP ZAP 始终返回代码 400 - 错误请求 - Daemon OWASP ZAP on Azure App Service always returns code 400 - Bad Request Azure App Gateway - 后端运行状况 404 错误 - Azure App Gateway - Backend Health 404 error 在 Asp.net web 应用程序部署在 azure 应用程序服务中,获取服务(.svc)端点的 404 未找到错误 - Getting 404 not found error for service(.svc) endpoints in Asp.net web application deployed on azure app service Azure 应用程序服务为 Spring 引导返回 404 Java 8 based war - Azure app service returning 404 for Spring boot Java 8 based war HTTP 在Azure上部署应用程序时出现413错误 - HTTP 413 Error When App is Deployed on Azure 逻辑应用中的 Azure 服务总线队列错误 - Azure service bus queue error in the logic app 0 function 在 Azure 应用程序服务自定义 docker 容器中加载错误 - 0 function loaded error in Azure app service custom docker container 在 Azure 上使用 PM2 运行 nextjs 时出错 在 Linux 上应用服务 - Error running nextjs with PM2 on Azure App Service on Linux 在 Azure 应用服务部署上安装 npm package 时出错 - Error installing npm package on Azure app service deploy 如何使用 HTTP 触发器解析 Azure Function App 中的多部分表单数据? (节点) - How to parse Multi-part form data in an Azure Function App with HTTP Trigger? (NodeJS)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM