我在 web.config
中将 Node.js 部署到 IIS 时遇到问题:
> <handlers>
> <add name="iisnode-ng-universal" path="dist/server.js" verb="*" modules="iisnode" />
> </handlers>
<rule name="ng-universal" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{HTTP_HOST}" pattern="test" />
</conditions>
<action type="Rewrite" url="dist/server.js" />
</rule>
我收到此错误:
这就是我的网络文件树的样子:
我尝试授予 IIS_IUSRS
和 IUSR
完全权限,但似乎不起作用。就像这篇文章建议的那样:
iisnode encountered an error when processing the request
最佳答案
如果您想通过服务器端渲染运行 Angular 应用程序:
1-创建一个新项目:
ng new anguniversal
2-启用服务器端渲染(SSR)
ng add @nguniversal/express-engine
第 1 步
首先执行下面给出的命令,使用 Express 服务器构建 Angular 应用程序。npm run build:ssr
现在您可以在项目文件夹中看到 dist 文件夹。
第 2 步
在 Windows 服务器中创建一个新文件夹(例如将其命名为 angular-universal),然后从此处的项目文件夹复制 dist 文件夹第 3 步
从 dist/anguniversal/server 文件夹复制 main.js 文件并将其直接粘贴到 Anguniversal 文件夹中。第 4 步
创建并打开 Web.config
文件(位于 Angular-universal 文件夹中)并向其中添加代码。
<?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>
</system.webServer>
</configuration>
第 5 步
安装IIS Node & URL Rewrite在服务器上。
第 6 步
第 7 步
在 IIS 中,转到“应用程序池”。对于您创建的网站( Angular 通用)。然后将 .NET CLR 版本更改为“无托管代码”。
完成,您可以查看结果。
关于node.js - 将 Angular Universal 部署到 IIS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49024686/