网站已部署在Azure上,但无法访问index.html

时间:2020-04-28 11:06:34

标签: azure azure-web-app-service azure-deployment

我正在尝试在Azure门户上基于类星构建和发布前端应用。

建造就可以了。

发布还可以,但是当我转到应用程序链接时,我看到标准的欢迎屏幕:

enter image description here

我通过SSH检查了已部署的代码,但它位于“ /home/site/wwwroot/index.html”上

enter image description here

如何在我的应用程序中指向正确的文件夹?谢谢!

1 个答案:

答案 0 :(得分:0)

首先有一个官方文档:how to set the default document in a Node.js app

它使用express来解决它,在其中使用以下代码创建index.js,然后重新启动您的应用程序,它将正常工作。

var express = require('express');
var server = express();
var options = {
index: 'index.html'
};
server.use('/', express.static('/home/site/wwwroot', options));
server.listen(process.env.PORT);

除此以外,还有另一种解决方法,请使用pm2,因为那已经是堆栈的一部分。为应用添加以下启动命令:

pm2 serve /home/site/wwwroot --no-daemon

enter image description here

重新启动应用程序后,它将从wwwroot中选择索引页面。