内部服务器错误 500,在 Azure 中托管来自 Visual Studio 2017 的 Node.js Express 4 应用程序模板

Internal server error 500, hosting Node.js Express 4 application template from Visual Studio 2017 in Azure

我从项目模板创建了一个项目:Visual Studio 2017 企业版中的“Basic Azure Node.js Express 4 Application”。

当我 运行 它在本地工作正常。 现在我使用下面的 Publish 菜单将其发布到 Azure:

我收到以下错误:

iisnode encountered an error when processing the request.

HRESULT: 0x2
HTTP status: 500
HTTP subStatus: 1001
HTTP reason: Internal Server Error

我没有对模板中的代码进行任何更改。

有什么想法吗?

我在 Visual Studio 2017 社区版中遵循了您的步骤。当我将 Express 应用程序发布到 Azure Web 应用程序时,我的浏览器出现以下错误。

The page cannot be displayed because an internal server error has occurred.

经过一些调查,我通过将 Web.config 文件更改为如下内容来修复它:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
    </staticContent>
    <modules runAllManagedModulesForAllRequests="false" />

    <iisnode watchedFiles="web.config;*.js;routes\*.js;views\*.pug" />

    <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{REQUEST_URI}" />
        </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>

  </system.webServer>

</configuration>    

另外,web.config 文件可以在 https://github.com/projectkudu/kudu/wiki/Using-a-custom-web.config-for-Node-apps 找到。

希望对您有所帮助。

我也遇到了500 server errors的问题,不知道为什么我启动站点时节点没有启动。您可以打开几种不同类型的日志,但 Diagnose and solve problems > Failed Request Tracing Logs 对我有帮助。

在日志中,我看到:

Warning:
ModuleName="RewriteModule", Notification="SEND_RESPONSE", HttpStatus="500", HttpReason="URL Rewrite Module Error.", HttpSubStatus="52", ErrorCode="2152071471", ConfigExceptionInfo=""
ErrorDescription="The expression "^server\app.js\/debug[\/]?" contains an escape sequence that is not valid."

问题归结为在 Azure 应用服务部署任务 web.config 中使用 Windows 路径分隔符 -NodeStartFile server\app.js 而不是 URL 路径分隔符 -NodeStartFile server/app.js参数.