1.开始

  本文部分内容均转载自文章:

http://www.hanselman.com/blog/InstallingAndRunningNodejsApplicationsWithinIISOnWindowsAreYouMad.aspx

https://github.com/tjanczuk/iisnode

  作者:SCOTT HANSELMAN

  标题:Installing and Running node.js applications within IIS on Windows - Are you mad?

  发布日期:2011.08.28

2.为什么我要在Windows IIS上运行Node.js

  首先,我主要编写的是Asp.Net应用程序,对windows和iis很熟悉,如果在使用Node.js生产的应用如果能部署在IIS上,那么我想很快就能将Node.js开发的应用发布在生产环境中。

  虽然在IIS运行Node.js上并不是最优选择,但是我主要开发企业级应用,单机并发访问量3K、4K足矣并不如大型互联网企业那样会遇到极大的并发、调优压力。

  最后微软有一帮人正在IIS上玩转Node.js,我表示跟着入坑试一试。

  • 进程管理:iisnode模块将会对node.exe进行简单而暴力的全生命周期的进程管理来增强其可靠性。你不必担心何时开启、结束node.exe,或者开着软件监控node.exe的运行状态。
  • 多核服务器的可扩展性:node.exe是一个单进程运行的程序,你需要额外编写基础设施代码来扩展其支持多核服务器,如果使用iisnode,你无须编写代码,将可以配置打开多个进程的node.exe,同时将HTTP请求均衡的负载到多个node.exe上。
  • 自动更新:iisnode将会监视js文件,如果有任何更新将会自动回收并重启node.exe加载新的js代码,你不必担心正在执行的http请求,因为这些请求将会仍然使用旧版本的js直至执行完毕。
  • HTTP访问日志:iisnode将会把HTTP请求中调用console.log输出的内存存储在output中,这些输出内容对于调试远程服务器来说是很重要的资源。
  • 混合开发:iisnode是IIS的一个模块而已,你在一个站点中可以包含node.js、php、asp.net等多个应用程序。
  • 少量的代码修改:为了将node.js程序部署在IIS中你还是需要修改一下node.js代码的,比如process.env.PORT
  • 集成管理经验:iisnode是IIS的一个模块,你可以用到IIS的一些特点如下
    • 端口共享,你可以在80端口下部署多个不同的应用asp.net、node.js、php啊,爱谁谁。
    • HTTPS支持
    • Url rewriting
    • 压缩
    • 缓存
    • 日志

3.如何在IIS上运行Node.js

  • 环境要求
    • Windows Vista, Windows 7, Windows 8, Windows Server 2008, or Windows Server 2012
    • IIS 7.x with IIS Management Tools and ASP.NET
    • WebSocket functionality requires IIS 8.x on Windows 8 or Windows Server 2012
    • URL rewrite module for IIS
      • (Win10:https://www.microsoft.com/en-us/download/details.aspx?id=47337)
    • Latest node.js build for Windows
  • 为IIS7.x/8.x安装iisnode扩展
    • 为 IIS 7.x/8.x 安装 iisnode : x86 或 x64 - 取决于你的操作系统
    • 安装示例, 以管理员权限打开CMD执行 %programfiles%\iisnode\setupsamples.bat
    • 浏览 http://localhost/node

4.学习iisnode

  通过上面安装node示例,查看示例发现iis下新增了一个node目录。

这个node目录运行在DefaultAppPool中(.Net 4.0集成)

  打开Express示例的文件夹,包括以下内容

  在Hello.js中定义了两个不同的接口myapp/foo、myapp/bar

1
2
3
4
5
6
7
8
9
10
11
12
13
var express = require('express');
 
var app = express.createServer();
 
app.get('/node/express/myapp/foo'function (req, res) {
    res.send('Hello from foo! [express sample]');
});
 
app.get('/node/express/myapp/bar'function (req, res) {
    res.send('Hello from bar! [express sample]');
});
 
app.listen(process.env.PORT);

  在Web.Config中指定了,Hello.js作为入口函数,同时将myapp/*请求映射给hello.js执行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<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="hello.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/express/myapp/foo
        http://localhost/node/express/myapp/bar
         
    -->
 
    <rewrite>
      <rules>
        <rule name="myapp">
          <match url="myapp/*" />
          <action type="Rewrite" url="hello.js" />
        </rule>
      </rules>
    </rewrite>
     
  </system.webServer>
</configuration>

  打开示例页http://localhost/node/express/readme.htm进一步查看调用情况

  最后打开Chrome浏览器,输入http://localhost/node/express/hello.js/debug,可以远程调试服务,真乃神器也。。

5.总结

  node.js + express即可以快速开发RestAPI和模版站点,又可以在iis中进行部署,远程调试,可以满足项目需要。

  以下内容参考:Debugger Don't work https://github.com/tjanczuk/iisnode/issues/396

  由于IIS7.X不支持WebSockets所以无法使用最新的远程调试器,但是可以通过配置旧的远程调试器(

1
<iisnode debuggerExtensionDll="iisnode-inspector.dll" />

)来支持IIS7.X,仅需要修改一下Web.Config配置,如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<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="hello.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/express/myapp/foo
        http://localhost/node/express/myapp/bar
         
    -->
 
    <rewrite>
      <rules>
        <rule name="myapp">
          <match url="myapp/*" />
          <action type="Rewrite" url="hello.js" />
        </rule>
      </rules>
    </rewrite>
    <iisnode debuggerExtensionDll="iisnode-inspector.dll" />
  </system.webServer>
</configuration>

  旧调试器就是丑点。。

http://www.cnblogs.com/mengkzhaoyun/p/5410185.html

crossplatform---Nodejs in Visual Studio Code 08.IIS的更多相关文章

  1. Nodejs in Visual Studio Code 08.IIS

    1.开始 本文部分内容均转载自文章: http://www.hanselman.com/blog/InstallingAndRunningNodejsApplicationsWithinIISOnWi ...

  2. Nodejs in Visual Studio Code 14.IISNode与IIS7.x

    1.开始 部署IISNode环境请参考:Nodejs in Visual Studio Code 08.IIS 部署Nodejs程序请参考:Nodejs in Visual Studio Code 1 ...

  3. Nodejs in Visual Studio Code 10.IISNode

    1.开始 Nodejs in Visual Studio Code 08.IIS : http://www.cnblogs.com/mengkzhaoyun/p/5410185.html 参考此篇内容 ...

  4. Nodejs in Visual Studio Code 11.前端工程优化

    1.开始 随着互联网技术的发展,企业应用里到处都是B/S设计,我有幸经历了很多项目有Asp.Net的,有Html/js的,有Silverlight的,有Flex的.很遗憾这些项目很少关注前端优化的问题 ...

  5. Nodejs in Visual Studio Code 01.简单介绍Nodejs

    1.开始 作者自己:开发人员,Asp.Net , html / js , restful , memcached , oracle ,windows , iis 目标读者:供自己以后回顾 2.我看No ...

  6. Nodejs in Visual Studio Code 04.Swig模版

    1.开始 设置Node_Global:npm config set prefix "C:\Program Files\nodejs" Express组件:npm install e ...

  7. Nodejs in Visual Studio Code 07.学习Oracle

    1.开始 Node.js:https://nodejs.org OracleDB: https://github.com/oracle/node-oracledb/blob/master/INSTAL ...

  8. Nodejs in Visual Studio Code 05.Swig+Bootstrap

    1. 开始 准备好Express+Swig的练习代码:https://github.com/Mengkzhaoyun/nodepractise 准备好AdminLTE后台管理模版:https://ww ...

  9. Nodejs in Visual Studio Code 12.构建单页应用Scrat实践

    1.开始 随着前端工程化深入研究,前端工程师现在碉堡了,甚至搞了个自己的前端网站http://div.io/需要邀请码才能注册,不过里面的技术确实牛.距离顶级的前端架构,目前博主应该是far away ...

随机推荐

  1. 使用 python 操作 redis

    1.安装pyredis (1)使用 # easy_install redis (2)直接编译安装 #wget https://pypi.python.org/packages/source/r/red ...

  2. [R] 回归拟合

    如下示例 > fit <- lm(y~x, data = data01) > summary(fit) Call: lm(formula = data01$P ~ data01$M, ...

  3. [转]linux14.04下caffe的安装步骤

     linux14.04下caffe的安装步骤   原文地址:http://blog.csdn.net/xiaoyang19910623/article/details/52997481?locatio ...

  4. ICE系列之3对象接口定义语言——slice

         Slice 定义由编译器编译到特定的实现语言 .编译器把与语言无关的定 义翻译成针对特定语言的类型定义和 API.开发者使用这些类型和 API 来 提供应用功能,并与 Ice 交互.用于各种 ...

  5. (Unity)Unity自定义Debug日志文件,利用VS生成Dll文件并使用Dotfuscated进展混淆,避免被反编译

    Unity自定义Debug日志文件,利用VS生成Dll文件并使用Dotfuscated进行混淆,避免被反编译. 1.打开VS,博主所用版本是Visual Studio 2013. 2.新建一个VC项目 ...

  6. 2006Jam的计数法

    题目描述 Description Jam是个喜欢标新立异的科学怪人.他不使用阿拉伯数字计数,而是使用小写英文字母计数,他觉得这样做,会使世界更加丰富多彩.在他的计数法中,每个数字的位数都是相同的(使用 ...

  7. getline函数的用法

    函数声明 bool getline(istream &in, string &s) 功能说明: 从输入流读入一行到变量string s,及时是空格也可以读入. –直到出现以下情况为止: ...

  8. 【转】APNs消息推送完整讲解

    https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificat ...

  9. Linux内核分析之计算机是如何工作的

    一.计算机工作原理 本周实验主要是反汇编C代码,生成汇编程序.冯·诺依曼理论的要点是:数字计算机的数制采用二进制,计算机应该按照程序顺序执行.人们把冯·诺依曼的这个理论称为冯·诺依曼体系结构.CPU通 ...

  10. VS2013_QT255开发相关技巧理解心得

    1. 在VS2013中打开QTCreater新建的项目 (1)通过双击.ui 打开QT的设计器,然后修改. (2)通过QT设计器,新建ui文件,放在VSQT的工程中 但是需要对此xxx.ui文件,进行 ...