首页 > 解决方案 > Azure 节点应用程序(在 Windows 应用程序服务上)无法运行

问题描述

作为应用程序的起点,我试图在 Azure 的节点上运行一个简单的 Hello World(在 Windows 应用程序服务上)。虽然目标是从 Azure DevOps 管道推送,但现在我只是按照本指南从 VS Code 进行部署。

应用程序按预期在本地运行,并且部署到 Azure 正在成功移动预期文件(包括 node_modules、package.json、app.js 和各种其他代码文件)。但该应用程序在 Azure 上无法正常运行。

任何请求都会导致 500 错误,无论是针对根 URL 还是明确针对/app.js. (我正在测试后者以查看它是否只是返回了文件,但这是一个 500 错误。)我已经启用了在 Azure 中可以找到的尽可能多的日志记录,但没有更多有用的信息浮出水面。只是带有通用 500 响应的 HTTP 请求的记录。

一些研究使我怀疑我需要web.config告诉 IIS 使用节点应用程序。在网上找到一些样本后,我得到了这个:

<?xml version="1.0" encoding="utf-8"?>
<!--
     This configuration file is required if iisnode is used to run node processes behind
     IIS or IIS Express.  For more information, visit:

     https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->

<configuration>
  <system.webServer>
    <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
    <webSocket enabled="false" />
    <handlers>
      <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
      <add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^app.js\/debug[\/]?" />
        </rule>

        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </rule>

        <!-- All other URLs are mapped to the node.js site entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="app.js"/>
        </rule>
      </rules>
    </rewrite>

    <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>

    <!-- Make sure error responses are left untouched -->
    <httpErrors existingResponse="PassThrough" />

    <!--
      You can control how Node is hosted within IIS using the following options:
        * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
        * node_env: will be propagated to node as NODE_ENV environment variable
        * debuggingEnabled - controls whether the built-in debugger is enabled

      See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
    -->
    <!--<iisnode watchedFiles="web.config;*.js"/>-->
  </system.webServer>
</configuration>

这对我来说很有意义。它告诉 IIS 使用iisnode、入口点文件、使用该入口点的 URL 映射等。重新部署后,我仍然得到通用的 500 响应。

我有点不知道在哪里看或在这个时候尝试什么。我怀疑构建一个 Hello World 应用程序并部署它应该很简单,而且我一定是遗漏了一些东西。但是什么?

标签: node.jsazure

解决方案


推荐阅读