温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何使用Node.js中iis部署运行node

发布时间:2021-09-14 11:34:45 来源:亿速云 阅读:273 作者:柒染 栏目:web开发

这篇文章给大家介绍如何使用Node.js中iis部署运行node,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

linux迁移到windows server,一言难尽。网上有说iis已经支持node了。IIS Node折腾了一下,没跑起来,估计兼容性不是那么好,索性放弃了。直接pm2部署了。

IIS Node地址:https://github.com/tjanczuk/iisnode/wiki/iisnode-releases

安装了IIS UrlRewrite 地址:https://www.iis.net/downloads/microsoft/url-rewrite

在站点根目录创建web.config, 内容如下

<?xml version="1.0" encoding="UTF-8"?> <configuration>     <system.webServer>         <rewrite>             <rules>                 <clear />                 <rule name="HTTP to HTTPS redirect" stopProcessing="true">                     <match url="(.*)" />                     <conditions logicalGrouping="MatchAll" trackAllCaptures="false">                         <add input="{HTTPS}" pattern="off" ignoreCase="true" />                     </conditions>                     <action type="Redirect" url="https://{HTTP_HOST}" redirectType="Found" />                 </rule>                 <rule name="root">                     <match url="^(.*)" />                     <conditions logicalGrouping="MatchAll" trackAllCaptures="false">                         <add input="{HTTP_HOST}" pattern="^chuchur.com$" />                     </conditions>                     <action type="Rewrite" url="http://127.0.0.1:7005/{R:1}" logRewrittenUrl="true" />                 </rule>                 <rule name="path">                     <match url="^(.*)" />                     <conditions logicalGrouping="MatchAll" trackAllCaptures="false">                         <add input="{HTTP_HOST}" pattern="^www.chuchur.com$" />                     </conditions>                     <action type="Rewrite" url="http://127.0.0.1:7005/{R:1}" />                 </rule>             </rules>         </rewrite>     </system.webServer> </configuration>

其中有三条规则,第一条是https的转发

第二条和第三条分别是把来源是主记录(chuchur.com)和别名(www.chuchur.com)的统统转发到node端口上。

剩下的就是一个SPA文档站点 (vue)

<?xml version="1.0" encoding="UTF-8"?> <configuration>     <system.webServer>         <rewrite>             <rules>                 <clear />                 <rule name="rest" stopProcessing="true">                     <match url="^rest/(.*)" />                     <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />                     <action type="Rewrite" url="http://127.0.0.1:7005/rest/{R:1}" />                 </rule>                 <rule name="root">                     <match url="(.*)" />                     <conditions logicalGrouping="MatchAll" trackAllCaptures="false">                         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />                         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />                     </conditions>                     <action type="Rewrite" url="/index.html" />                 </rule>             </rules>         </rewrite>         <staticContent>             <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff" />         </staticContent>     </system.webServer> </configuration>

一起有 2 条规则,第一条是一个proxy, 把/rest/转发到node端口的/rest/上。第二条是vue路由history模式的地址Rewrite

关于如何使用Node.js中iis部署运行node就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI