无法获取 index.html Azure Linux Web 应用程序 [英] Cannot GET index.html Azure Linux Web App

查看:21
本文介绍了无法获取 index.html Azure Linux Web 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 Microsoft Azure 中创建了一个 Linux Web 应用程序.该应用程序是用 React(html 和 Javascript)静态编写的.我们将代码复制到 wwwroot 文件夹中,但应用程序仅显示 hostsstart.html 并且当我们尝试获取页面 index.html 时出现此错误:无法获取/index.html

我们在 GitHub (

  • 在 ssh 终端中,通过命令行导航到/home/site/wwwroot
  • 使用以下代码在那里创建 index.js:

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

  • 注意:一定要在这个文件夹中运行 npm install --save express 否则你的应用服务会在启动时崩溃

  • 如果应用服务没有自动重启,请务必重启

  • We created a Linux Web App in Microsoft Azure. The application is static written with React (html and Javascript). We copied the code into the wwwroot folder, but the application only showing only hostingstart.html and when we try to get page index.html we have this error: Cannot GET /index.html

    We tried with a sample of Azure in GitHub (https://github.com/Azure-Samples/html-docs-hello-world) but the error is the same. The url is this: https://consoleadmin.azurewebsites.net/index.html

    Last week the application was running correctly.

    We forget to do something?

    解决方案

    Ok you are gonna love this. This happened to me today also. Same exact thing. I am pretty sure the azure team flipped a switch somewhere and we fell through a crack.

    I found this obscure answer with no votes and it did the trick (with a little extra finagling)

    BONUS! this also fixed my router issues I was having only on the deployed site (not local):

    Credit: @stormwild: Default documents not serving on node web app hosted on Azure

    From @stormwild's post see here: https://blogs.msdn.microsoft.com/waws/2017/09/08/things-you-should-know-web-apps-and-linux/#NodeHome

    Steps:

    1. Go to your azure portal, select your app service and launch ssh
    2. In ssh terminal, navigate via command line to /home/site/wwwroot
    3. create index.js there with the following code:

      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);
      

    4. NOTE: Be sure to run npm install --save express also in this folder else your app service will crash on startup

    5. Be sure to restart your app service if it doesn't do so automagically

    这篇关于无法获取 index.html Azure Linux Web 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆