一招教你使用Node.js中iis部署运行node(附代码)

 6080

本篇文章给大家介绍怎么使用Node.jsiis部署运行node,我们一起看看怎么做。


一招教你使用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, 内容如下

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3.     <system.webServer>
  4.         <rewrite>
  5.             <rules>
  6.                 <clear />
  7.                 <rule name="HTTP to HTTPS redirect" stopProcessing="true">
  8.                     <match url="(.*)" />
  9.                     <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
  10.                         <add input="{HTTPS}" pattern="off" ignoreCase="true" />
  11.                     </conditions>
  12.                     <action type="Redirect" url="https://{HTTP_HOST}" redirectType="Found" />
  13.                 </rule>
  14.                 <rule name="root">
  15.                     <match url="^(.*)" />
  16.                     <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
  17.                         <add input="{HTTP_HOST}" pattern="^chuchur.com$" />
  18.                     </conditions>
  19.                     <action type="Rewrite" url="http://127.0.0.1:7005/{R:1}" logRewrittenUrl="true" />
  20.                 </rule>
  21.                 <rule name="path">
  22.                     <match url="^(.*)" />
  23.                     <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
  24.                         <add input="{HTTP_HOST}" pattern="^www.chuchur.com$" />
  25.                     </conditions>
  26.                     <action type="Rewrite" url="http://127.0.0.1:7005/{R:1}" />
  27.                 </rule>
  28.             </rules>
  29.         </rewrite>
  30.     </system.webServer>
  31. </configuration>

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

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

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

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3.     <system.webServer>
  4.         <rewrite>
  5.             <rules>
  6.                 <clear />
  7.                 <rule name="rest" stopProcessing="true">
  8.                     <match url="^rest/(.*)" />
  9.                     <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
  10.                     <action type="Rewrite" url="http://127.0.0.1:7005/rest/{R:1}" />
  11.                 </rule>
  12.                 <rule name="root">
  13.                     <match url="(.*)" />
  14.                     <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
  15.                         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  16.                         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  17.                     </conditions>
  18.                     <action type="Rewrite" url="/index.html" />
  19.                 </rule>
  20.             </rules>
  21.         </rewrite>
  22.         <staticContent>
  23.             <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff" />
  24.         </staticContent>
  25.     </system.webServer>
  26. </configuration>

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

阿里云是个坑货啊,买了2年的CES,到期了, 我就想着不续费,重新转到香港算了,这样我在香港搭个VPN,又便宜,然后顺利的解决了翻墙的问题。

买了台Window Server2008,一切准备就绪,什么都部署好了。结果没过两周,提示域名备案失效,个人认证失效,总之之前做的一切工作,都没用了。再次认证提示,服务器不在境内。香港不行。要我迁移回来。

说实在的香港的主机真的不怎么样,经常登录不上,vpn也是时好时坏,基本也就是连不上,正好又出了政策,未备案的域名停止解析。这下网站基本就挂了。

于是又迁移回国内了。重新备案,重新个人认证一堆...

又从Window切到Linux。真的是很扯淡...

留个记录,怕哪天又要去折腾IIS


TAG标签:
本文网址:https://www.zztuku.com/detail-9209.html
站长图库 - 一招教你使用Node.js中iis部署运行node(附代码)
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐