【问题标题】:Azure web app giving HTTP error 500 when viewed, how can this be fixed?Azure Web 应用程序在查看时出现 HTTP 错误 500,如何解决?
【发布时间】:2022-12-19 14:21:13
【问题描述】:

尝试将我的移动 Web 应用程序上传到 Azure 已关注 https://learn.microsoft.com/en-us/azure/app-service/quickstart-nodejs?tabs=windows&pivots=development-environment-vscode

最终只是收到无法处理请求 HTTP 错误 500 的错误

网络应用程序在本地工作,所以我不知道问题是什么 一位朋友告诉我,这可能是因为 views 文件夹中的所有网页都是 .ejs 文件,而它们应该是 HTML。

【问题讨论】:

    标签: azure azure-web-app-service


    【解决方案1】:

    我遵循了您提供的相同文档,并且能够毫无问题地访问该应用程序。

    • 使用以下命令创建Node.js 应用程序。
    npx express-generator myExpApp19Dec --view ejs
    

    • 导航到应用程序根目录 (myExpApp19Dec) 并运行 npm install

    • node_modules 文件夹将在目录的根目录下创建。
    • 运行npm start 在本地启动并运行应用程序。

    • 从 VSCode 打开应用程序。

    将 Web 应用部署到 Azure 应用服务的步骤

    • 登录Azure => 点击Azure Icon => 选择你的Subscription => App Services

    web app name - ExpressApp19Dec
    runtime stack - Node 18 LTS
    OS - Windows
    Location - East US
    

    • 部署后,当我尝试访问该应用程序时,我立即收到以下错误。

    • 按照文档中的建议在应用程序设置中添加SCM_DO_BUILD_DURING_DEPLOYMENT

    • 导航到 VSCode => Your App => Application Settings => Add New Setting 中已部署的 App 文件夹。

    • 我们甚至可以从Azure Portal => App Service => Configuration 部分添加这个Application Setting。当我们从 Azure 门户添加 Application Setting 时,可以排除重新部署选项。

    • 重新部署应用程序以获取最新更改。

    • 确保在 KUDU 控制台中部署的应用程序的根目录中创建了 web.config 文件。 KUDU 控制台的路径 -https://YourAppServiceName.scm.azurewebsites.net/DebugConsole

    我自动生成的web.config 文件

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.webServer>   
        <webSocket enabled="false" />
        <handlers>     
          <add name="iisnode" path="bin/www" verb="*" modules="iisnode"/>
        </handlers>
        <rewrite>
          <rules>      
            <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
              <match url="^bin/www/debug[/]?" />
            </rule>
           
            <rule name="StaticContent">
              <action type="Rewrite" url="public{PATH_INFO}"/>
            </rule>       
            <rule name="DynamicContent">
              <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
              </conditions>
              <action type="Rewrite" url="bin/www"/>
            </rule>
          </rules>
        </rewrite>   
       
        <security>
          <requestFiltering>
            <hiddenSegments>
              <remove segment="bin"/>
            </hiddenSegments>
          </requestFiltering>
        </security>  
        <httpErrors existingResponse="PassThrough" />     
      </system.webServer>
    </configuration>
    
    • 现在我可以访问应用程序了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-22
      • 2021-07-13
      • 1970-01-01
      • 2015-11-26
      • 2020-09-03
      • 2021-10-23
      • 1970-01-01
      • 2019-06-09
      相关资源
      最近更新 更多