【问题标题】:Error in hosting Angular Universal in IIS : iisnode encountered an error when processing the request在 IIS 中托管 Angular Universal 时出错:iisnode 在处理请求时遇到错误
【发布时间】:2022-01-22 15:26:00
【问题描述】:

我试图动态更改我的 Angular 8 元标记以用于 Facebook 共享。
我在 C# 上有后端 API。
但除了将现有应用程序转换为服务器端的选项外,我在任何地方都找不到任何解决方案。

因此,我正在尝试在 Windows Server 2019 的 IIS 中托管我的 Angular 8 通用应用程序。
我在托管站点的根目录中有 dist 文件夹、main.js 和 web.config 文件。
我已经在服务器中安装了 iisnode。
当我浏览该站点时,会在根目录中创建一个空白 iisnode 文件夹。
我已将 IIS_IUSR 和 IUSR 设置为根目录的完全控制权限。
但我收到以下错误:

Error

我的文件夹结构如下:

Folder

我的web.config如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>        
      <handlers>
        <add name="iisnode" path="main.js" verb="*" modules="iisnode" />
      </handlers>
      <rewrite>
        <rules>
            <rule name="DynamicContent">
                 <match url="/*" />
                 <action type="Rewrite" url="main.js" />
            </rule>
            <rule name="StaticContent" stopProcessing="true">  
                  <match url="([\S]+[.](jpg|jpeg|gif|css|png|js|ts|cscc|less|ico|html|map|svg))" />
                  <action type="None" />
            </rule>  
       </rules>
      </rewrite>
        <staticContent>
          <clientCache cacheControlMode="UseMaxAge" />
          <remove fileExtension=".svg" />
          <remove fileExtension=".eot" />
          <remove fileExtension=".ttf" />
          <remove fileExtension=".woff" />
          <remove fileExtension=".woff2" />
          <remove fileExtension=".otf" />
          <mimeMap fileExtension=".ttf" mimeType="application/octet-stream" />
          <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
          <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
          <mimeMap fileExtension=".woff" mimeType="application/x-woff" />
          <mimeMap fileExtension=".woff2" mimeType="application/x-woff" />
          <mimeMap fileExtension=".otf" mimeType="application/otf" />
         </staticContent> 
<iisnode node_env="production" nodeProcessCountPerApplication="0" nodeProcessCommandLine="C:\Program Files\nodejs\node.exe" interceptor="C:\Program Files\iisnode\interceptor.js" />
</system.webServer>
  </configuration>

我被这个问题困住了,无法继续。
请帮帮我。

更新(2021 年 12 月 23 日):
我对角度代码进行了一些更改,该问题已得到解决。但是会显示一个新错误,如下所示:

iisnode在处理请求时遇到错误。

HRESULT:0x2 HTTP 状态:500 HTTP 子状态:1002 HTTP 原因: 内部服务器错误 您收到此 HTTP 200 响应是因为 system.webServer/iisnode/@devErrorsEnabled 配置设置为 '真实'。

除了node.exe进程的stdout和stderr的日志, 考虑使用调试和 ETW 跟踪来进一步诊断 问题。

node.exe进程生成到stderr的输出的最后64k 如下图:

应用程序抛出未捕获的异常并终止:错误: 找不到模块 'zone.js/dist/zone-node' 需要堆栈:

  • C:\inetpub\wwwroot\AdvAngularServer\main.js
  • C:\Program Files (x86)\iisnode\interceptor.js 在 Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15) 在 Function.Module._load (internal/modules/cjs/loader.js:725:27) 在 Module.require (internal/modules/cjs/loader.js:952:19) 在需要(内部/模块/cjs/helpers.js:88:18) 在 Object.b6Xn (C:\inetpub\wwwroot\AdvAngularServer\main.js:1:6605) 在 webpack_require (C:\inetpub\wwwroot\AdvAngularServer\main.js:1:317) 在 Module.uj+Y (C:\inetpub\wwwroot\AdvAngularServer\main.js:1:21026) 在 webpack_require (C:\inetpub\wwwroot\AdvAngularServer\main.js:1:317) 在 Object.0 (C:\inetpub\wwwroot\AdvAngularServer\main.js:1:2902) 在 webpack_require (C:\inetpub\wwwroot\AdvAngularServer\main.js:1:317)

有什么想法吗?

【问题讨论】:

  • 如错误信息提示,您需要更多信息来解决您的问题。您可以使用错误消息中提到的失败请求跟踪或调试以及 ETW 跟踪。
  • 我使用了失败的请求跟踪,发现一条消息:iisnode was unable to establish named pipe connection to the node.exe process before the process terminated
  • 我需要在任何 Angular 文件中为 IISNode 编写任何代码吗?我实际上正在将我的常规应用程序转换为通用应用程序。请帮忙。
  • 根据此消息很难重现您的问题,建议您通过support.microsoft.com开一个案例。
  • 请在上面的主要问题中查看我的更新。我已经更新了新的错误消息。谢谢。

标签: node.js angular iis angular-universal iisnode


【解决方案1】:

有一个用户“NetworkServices”或类似的东西...您已经尝试将此用户添加到 Windows 权限?我遇到了 wordpress 的问题,我可以用它来解决。

我认为您没有 dist 文件夹的权限,或者您的模块 zone-node 的代码路径错误

【讨论】:

    【解决方案2】:

    我通过在 package.json 中添加 --bundleDependencies all 解决了这个问题。
    谢谢。

    【讨论】:

      猜你喜欢
      • 2014-07-24
      • 2015-10-20
      • 2020-02-02
      • 2014-01-12
      • 2020-10-12
      • 2014-06-19
      • 2018-08-03
      • 2014-03-18
      • 1970-01-01
      相关资源
      最近更新 更多