【问题标题】:Azure Webapp : What is the correct web.config in this case?Azure Webapp:在这种情况下,正确的 web.config 是什么?
【发布时间】:2018-05-03 15:21:45
【问题描述】:

我们目前在 Windows WebApp 上部署 Node.js 应用程序时遇到了一些麻烦,我们怀疑问题出在 web.config 文件中。

这是项目目录结构:

我们使用默认的 web.config 并进行了一些更改: 应用文件是app.js,公共文件夹是dist/

<?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="dist{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 重写模块正在将 dist/ 添加到 URL,如下所示:http://xxxxxxx.azurewebsites.net/dist/

我们有一个 iisnode 错误消息:

HRESULT:0x2

HTTP 状态:500

HTTP 子状态:1001

HTTP 原因:内部服务器错误

我尝试检查失败的请求跟踪日志,但没有记录失败的请求。

有人能告诉我我的情况发生了什么吗?


编辑:

我决定从头开始并创建一个新的网络应用程序。

我使用 kudu 控制台构建了 node.js 应用程序,并且(使用相同的 web.config)服务器现在可以正确获取 dist/ 中的 index.html 文件.

到目前为止一切顺利,我们正确地登陆了登录页面。

现在的问题是 iisnode 无法使用用户凭据处理 POST 请求。

按照 Julien 的建议,我尝试更改应用程序的虚拟目录并出现不同的错误:

第一种情况:

虚拟目录: /
路径: site\wwwroot
错误:同上的iisnode错误 p> 第二种情况:

虚拟目录: /
路径: site\wwwroot\dist
错误:您要查找的资源有已被删除、名称已更改或暂时不可用。

对此有什么想法吗?
谢谢

【问题讨论】:

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


    【解决方案1】:

    其实你的web.config是正确的。

    您可以尝试将 app.js 的内容替换为以下最小的 Node.js 应用,看看它是否有效。

    var http = require('http');
    
    var server = http.createServer(function(req, res) {
      res.writeHead(200);
      res.end('Hello Azure');
    });
    server.listen(process.env.PORT);
    

    重要提示:当脚本在 Azure Web 服务上运行时,请使用 process.env.PORT 作为脚本中的端口。

    【讨论】:

    • 嗨 Aaron,是的,它确实适用于那个最小的 Node.js 应用
    • 那么,您能否编辑您的问题以包含您的 app.js?
    • 或者您可以启用 stdout 和 stderr 的日志记录以进行进一步的故障排除。关于如何做到这一点,请参阅this post
    • 是的,你需要使用process.env.PORT
    【解决方案2】:

    根据您将应用推送到网络应用的方式,您可以尝试:

    • 使用 PROJECT 环境变量指定您的应用位于 dist 文件夹中,如 here 所述。
    • 在 Web 应用程序设置中定义一个虚拟目录,以指定应用程序的根文件夹为 site\wwwroot\dist。您可以找到配置 here 的 JSON 示例或使用 Azure 门户中的应用程序设置边栏选项卡。

    希望对你有帮助

    朱利安

    【讨论】:

    • 您好 Julien,我在 Azure 上构建应用时遇到问题,由于某种原因它找不到 ./node_modules/semantic-ui-css/semantic.css。所以我从头开始并且能够构建。现在我有一个不同的错误并编辑了问题。
    猜你喜欢
    • 1970-01-01
    • 2013-04-23
    • 2011-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-14
    • 1970-01-01
    相关资源
    最近更新 更多