开发者

Can you use node.js with IIS?

This may be an extremely simple 开发者_如何学运维quesiton, but can I use node.js in a windows server 2008 environment with IIS? Is there a "Microsoft" library or some other solution that works better?


Sure you can, check out the IISNode Project.


You can install Node.js on Windows, but it is its own server, so unless you're using IIS as a proxy to it, there's no need for IIS at all. Note, though, the following as quoted from Node.js's installation instructions:

Neither [Windows] builds are satisfactorily stable but it is possible to get something running.


You essentially have two routes for running a Node.js application via IIS.

  • IISNode
  • Reverse Proxy using Application Request Routing

If you are dedicating an entire application to Node.js and simply need the public facing endpoint to work through your existing IIS Application, I would suggest using ARR to route the entire site through. I'm doing this for a couple of projects, and it works fairly well.

To be honest, I haven't liked IISNode, as it seems like you are making alien endpoints in your node code vs. IIS. It works, and if you are targeting Azure in particular it may be your best option. It also may be the best option if you have to shoe horn it into an existing .Net application.


I have been using Node on Windows with Cygwin and had few problems. You can use IIS to serve on default port 80 and run your Node apps on different ports.

If you want to proxy then most are using Nginx.


You can build node.js on Windows, but it's not recommended to use it due to possible stability issues. If IIS is using thread based pools then you shouldn't even use it as a reverse proxy (on linux based systems nginx is usually used to do this) for node.js because pool may quickly become fully loaded. If you want something similar to node.js on windows then you should try to look at manos.


I wanted to make it as easy as possible.

Issues with iisnode

  1. I installed iisnode and ran the samples with no problem but...

  2. I tried to deploy it on IIS with iisnode, but I had to bundle my meteor app and then deploy it as a node app. The problem I ran into discouraged me. I could not get fibers to install at all. compilation process kept trowing errors, so I gave up.

Reverse Proxy IIS

What I did to solve this for me is use a reverse proxy on IIS.

see my post on meteor forum

My final web.config entry was:

I did the same, however, the way I had the reverse proxy on IIS to use a sub folder on the domain threw me of.

I was not aware that by using ROOT_URL we could specify the a sub path.

example, if i run the following command inside my meteor app folder:

set ROOT_URL=http://localhost:3100/n/todos && meteor

I will be able to access my app at http://localhost:3100/n/todos, notice I omitted the trailing /. And if we try to surf to the address http://localhost:3100/n or http://localhost:3100/ will give us an error Unknown path.

So, when I first setup the reverse proxy, I was getting the Unknown Path error every time.

Turns out that on my IIS config, I have to specify the http://localhost:3100/n/todos as the url value on the action, please notice the "n/todos" at the end.

So my rewrite rule ended up like this: [file @ c:/inetpub/wwroot/web.config]

```  
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="TODOs meteor app. Route the requests" stopProcessing="true" enabled="true">
          <match url="^n/todos/(.*)" />
          <conditions>
            <add input="{CACHE_URL}" pattern="^(https?)://" />
          </conditions>
          <action type="Rewrite" url="{C:1}://localhost:3100/n/todos/{R:1}" /> <!-- I was missing the /n/todos here -->
          <serverVariables>
            <set name="HTTP_ACCEPT_ENCODING" value="" />
          </serverVariables>
        </rule>
      </rules>
      <outboundRules>
        <rule name="TODOs ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" enabled="false">
          <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://localhost:3100/(.*)" />
          <action type="Rewrite" value="/n/todos/{R:2}" />
        </rule>
        <rule name="TODOs RewriteRelativePaths" preCondition="ResponseIsHtml1" enabled="false">
          <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/(.*)" negate="false" />
          <action type="Rewrite" value="/n/todos/{R:1}" />
        </rule>
        <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
          <match filterByTags="A, Form, Img" pattern="^http(s)?://localhost:3100/(.*)" />
          <action type="Rewrite" value="http{R:1}://localhost/{R:2}" />
        </rule>
        <preConditions>
          <preCondition name="ResponseIsHtml1">
            <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
          </preCondition>
        </preConditions>
      </outboundRules>
    </rewrite>
  </system.webServer>
</configuration>
```

Thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜