Azure Web 部署不显示网页

Azure web deployment not displaying web page

我正在编写一个简单的 nodejs 应用程序以部署到 azure。

该应用程序运行正常,100%,但我必须管理管理事务的网页拒绝加载。

它总是显示内部服务器错误。我正在使用 express 并查看日志,但它们没有任何用处。该应用程序没有崩溃,所以我不明白为什么它不会显示。

这是我用于测试的简单的 hello world 代码,即使这样也不会显示。

var express = require('express');
var app = express();

app.use(express.static('website'));
app.listen(80);

有人知道问题出在哪里吗?

编辑:我忘了包括我确实设置了端口环境变量

var port = process.env.PORT || 80;
var baseHost = process.env.WEBSITE_HOSTNAME || 'localhost';

那是我 server.js 的顶部,对此感到抱歉。

关注此博客以获得在 Azure 上运行的 Node.js 应用程序。我最近用它来做演示,效果很好。

Create a Node.js web app in Azure App Service

您必须使用 GIT 和持续部署让 Azure App Services 识别和设置正确的部分以使您的节点应用程序正常运行,它还会自动为您处理节点包。

希望这对您有所帮助,TehDude

尝试打开日志记录以更好地了解正在发生的事情

来自How to debug a Node.js web app in Azure App Service

To enable the logging of stdout and stderr streams, you must create an IISNode.yml file at the root of your Node.js application and add the following:

loggingEnabled: true

This enables the logging of stderr and stdout from your Node.js application.

The IISNode.yml file can also be used to control whether friendly errors or developer errors are returned to the browser when a failure occurs. To enable developer errors, add the following line to the IISNode.yml file:

devErrorsEnabled: true

Once this option is enabled, IISNode will return the last 64K of information sent to stderr instead of a friendly error such as "an internal server error occurred".

我猜当 运行 在 Azure 应用服务上时,您的应用正在侦听错误的端口。 您必须从环境变量 "process.env.port"

中获取端口号
var app = require('express')();
var port = process.env.port || 8080; // 8080 for local or whatever number u want
var listener = app.listen(port, function(){
    console.log('Listening on port ' + port); 
});

Node.js Azure Web Apps 服务上的应用程序 运行ning 托管在 IIS 上,通过 IISNode 处理映射,它提供了一个命名管道来接收传入的请求,而不是像您那样的 TCP 端口在本地 运行ning 时使用。

此命名管道已在 Node.js 运行 时间在 Azure Web Apps 上定义为端口。您可以在您的应用程序中定义端口,例如:process.env.PORT || 3000,您的应用程序可以使用它 运行 在 Azure 上或本地。