我有一个要在windows上运行的Nest.js应用程序。我安装了iisnode模块github.com/tjanczuk/iisnode,并在IIS上创建了一个新的网站和应用程序。
我可以打电话给我的Api端点,但收到以下消息:
警告:由于安全性和可用性问题,缓冲区()不再受欢迎。请改用Buffer.alloc()、Buffer.allocUnsafe()或Buffer.from()方法。
问题是,我不使用Buffer() im我的代码,它只在我的项目中使用的一些节点模块中使用。
在我花更多时间解决不推荐的警告之前,我只是想确定,在IIS上使用iisnode运行nest.js应用程序通常是可能的吗?
非常感谢你的帮助
这是我的web.config文件
<configuration>
<system.webServer>
<!-- indicates that the hello.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="main.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="sendToNode">
<match url="/*" />
<action type="Rewrite" url="main.js" />
</rule>
</rules>
</rewrite>
...
</system.webServer>
</configuration>
'''
发布于 2022-01-15 01:45:54
从零开始
在这里,我们将在iis服务器上进行一个crerate hello world项目和主机。
因此,在全球范围内安装nest您的偏好--我使用的是这种方法
npm install -g @nestjs/cli
所以创建新的巢项目
nest new myhost
然后按this=>移动到该文件夹
cd myhost
npm run start
在这里,我将3000端口改为4444端口,您可以根据自己的意愿进行更改。
只需构建您的项目,现在创建dist文件夹
npm run build
现在将pm2节点包安装为后台服务pm2link
npm install pm2 -g
现在您可以检查链接http://localhost:4444/了。
现在开放iis (互联网信息服务)
==> Add Website
==>Add site name
==>Add Physical path as you build folder
==> Add Port not 4444 because our node project running on that port so use different port
现在单击url重写将重定向端口4445 (iis宿主端口)重定向到4444(项目运行端口)。
选择反向代理
添加反向代理规则
现在检查两个端口上的浏览器工作。
web.config可能会非常喜欢上面的配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:4444/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
发布于 2021-09-05 18:58:55
如果有人仍在寻找如何在IIS上托管NestJ应用程序的答案,则必须使用URLRewrite
和PM2 (不需要IISNode):
在您的IIS中安装URLRewrite
模块。
安装PM2
的想法是通过PM2运行NestJs应用程序,然后在IIS中设置反向代理,将所有入站请求重定向到正在运行的NestJS应用程序.。
首先,确保应用程序是通过PM2运行的。导航到main.js
文件所在的文件夹,并运行pm2 start main.js
然后,将NestJS应用程序配置为在IIS中选择的端口上运行。
然后,在web.config
中设置反向代理设置,将其重定向到运行NestJ应用程序的实际端口。我的web.config
如下所示,其中我将入站请求重定向到localhost:3333
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:3333/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
就是这样。您的NestJ应用程序现在将成功地在IIS上运行。
有关更多信息,请参考这个精彩的链接。
https://stackoverflow.com/questions/61273771
复制