IIS 运行 Nodejs — 我大脑正常着呢!
发布于 13 年前 作者 be5invis 20617 次浏览 最后一次编辑是 8 年前

今天本来很突发奇想的查有没有在 node 上面做游戏的库,结果后来就走神到查如何用 node 勾搭 IIS 去了。可我没想到还真有人把它们给撮合了起来 —— <a href=“https://github.com/tjanczuk/iisnode”>http://github.com/tjanczuk/iisnode</a>。iisnode。 <br/> <br/>看了些介绍,下面是一个很简单的安装过程: <br/><ul> <br/> <li>首先,从官网下 node.exe,放进 C:\node\ 目录。(个人尝试:你也可以用 mklink 做个链接,放别的地方)</li> <br/> <li>设置好 NODE_PATH 变量</li> <br/> <li>确保 IIS 为 7.0,并且安装了 URL 重写</li> <br/> <li>下载 iisnode,放进一个文件夹(我是放在 C:\inetpub\iisnode)。确保 Users 组可以读写此文件夹</li> <br/> <li>以管理员权限运行一个 cmd,cd 进刚才那里,运行 install.bat。完成。打开 http://localhost/node 看看效果吧。</li> <br/></ul> <br/>现在你应该就可以直接在 IIS 里面添加处理程序映射(Web.config: <handlers>)了。(方法:把某个 .js 文件关联到 iisnode 模块。)iisnode 的官方例子还是比较完备的,从 helloworld 到使用 express 的小站点都有。各位可以自行围观。 <br/> <br/>下面附上官网里 express 小站的 web.config,很简单不是吗? <br/><pre><configuration> <br/> <system.webServer> <br/> <br/> <!-- indicates that the hello.js file is a node.js application <br/> to be handled by the iisnode module --> <br/> <br/> <handlers> <br/> <add name=“iisnode” path=“hello.js” verb="" modules=“iisnode” /> <br/> </handlers> <br/> <br/> <!-- use URL rewriting to redirect the entire branch of the URL namespace <br/> to hello.js node.js application; for example, the following URLs will <br/> all be handled by hello.js: <br/> <br/> http://localhost/node/express/hello/foo <br/> http://localhost/node/express/hello/bar <br/> <br/> --> <br/> <br/> <rewrite> <br/> <rules> <br/> <rule name=“hello”> <br/> <match url="hello/" /> <br/> <action type=“Rewrite” url=“hello.js” /> <br/> </rule> <br/> </rules> <br/> </rewrite> <br/> <br/> <!-- exclude node_modules directory and subdirectories from serving <br/> by IIS since these are implementation details of node.js applications --> <br/> <br/> <security> <br/> <requestFiltering> <br/> <hiddenSegments> <br/> <add segment=“node_modules” /> <br/> </hiddenSegments> <br/> </requestFiltering> <br/> </security>
<br/> <br/> </system.webServer> <br/></configuration></pre> <br/>小站本身的源码也很简单,只是把原来监听的 80 端口改成 <pre><code>process.env.PORT</pre></code> <br/><pre>var express = require(‘express’); <br/> <br/>var app = express.createServer(); <br/> <br/>app.get(’/node/express/hello/foo’, function (req, res) { <br/> res.send(‘Hello from foo! [express sample]’); <br/>}); <br/> <br/>app.get(’/node/express/hello/bar’, function (req, res) { <br/> res.send(‘Hello from bar! [express sample]’); <br/>}); <br/> <br/>app.listen(process.env.PORT);</pre>

5 回复

还有是以IIS5,6的 <br/> <br/>最主要的问题是,我想跑IIS我就想用SQLServer

Node 上面曾经出现过一个 node-tds 的数据库驱动,但是作者给坑掉了 - -

Node 上面曾经出现过一个 node-tds 的数据库驱动,但是作者给坑掉了 – - <br/> <br/> <br/>-.-!!那个node-tds 试过,貌似还真用不了.

Scott Hanselman也给了个在Windows和IIS上跑node.js的解决方案http://www.hanselman.com/blog/WebMatrixAndNodejsTheEasiestWayToGetStartedWithNodeOnWindows.aspx

回到顶部