1:下载最新的iisnode安装程序,装上: https://github.com/tjanczuk/iisnode/wiki/iisnode-releases
2:安装 IIS URL Rewrite https://www.iis.net/downloads/microsoft/url-rewrite
3:找到iisnode的安装路径,已管理员身份运行 setupsamples.bat
运行出现以下内容,证明成功了:
运行这个地址:
出现以下内容
最后在项目根目录创建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="index.js" verb="*" modules="iisnode" />
</handlers>
<!-- use URL rewriting to redirect the entire branch of the URL namespace
to hello.js node.js application; for example, the following URLs will
all be handled by hello.js:
http://localhost/node/urlrewrite/myapp
http://localhost/node/urlrewrite/myapp/foo
http://localhost/node/urlrewrite/myapp/foo/bar/baz?param=bat
-->
<rewrite>
<rules>
<rule name="myapp">
<match url="/*" />
<action type="Rewrite" url="index.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>最后忘记了一点很重要,就是我们在监听的地方要加上:process.env.PORT
例如:app.listen(process.env.PORT || 3000);
版权声明:本文为yunchenglk原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。