你能在IIS中使用node.js吗?

5

这可能是一个非常简单的问题,但我可以在安装了IIS的Windows Server 2008环境中使用Node.js吗?是否有“Microsoft”库或其他更好的解决方案可用?


建立Windows + IIS + Node.js + Mongodb 环境教程,快速构建TODO应用程序。详情参见http://www.amazedsaint.com/2011/09/creating-10-minute-todo-listing-app-on.html - amazedsaint
6个回答

6

4
您可以在Windows上安装Node.js,但它是自己的服务器,所以除非您使用IIS作为代理,否则根本不需要使用IIS。请注意,以下是引用自Node.js的安装说明的内容:
“两种[Windows]构建都不够稳定,但有可能运行一些东西。”

4

您可以通过两种方式在IIS上运行Node.js应用程序。

如果您要将整个应用程序专门用于Node.js,并且仅需要公共终端点通过现有的IIS应用程序工作,我建议使用ARR将整个站点路由。 我正在为几个项目执行此操作,效果还不错。

老实说,我不喜欢IISNode,因为它似乎是在您的节点代码中创建外来终端点而不是IIS。 它能工作,如果您特别针对Azure,则可能是最佳选择。 如果您必须将其塞入现有的.Net应用程序中,则也可能是最佳选择。


2

我一直在Windows上使用Cygwin和Node,遇到了一些问题。你可以使用IIS在默认端口80上提供服务,并在不同的端口上运行Node应用程序。

如果想要代理,大多数人都使用Nginx。


1

你可以在Windows上构建node.js,但由于可能存在稳定性问题,不建议使用它。如果IIS正在使用基于线程的池,则甚至不应将其用作反向代理(在基于Linux的系统上,通常使用nginx来执行此操作)以用于node.js,因为池可能会很快变得完全加载。如果您想要类似于Windows上的node.js的东西,那么您应该尝试查看manos


0

我想尽可能地让它变得简单。

iisnode的问题

  1. 我安装了iisnode并运行了示例,没有任何问题,但是...

  2. 我尝试使用iisnode在IIS上部署它,但我必须捆绑我的meteor应用程序,然后将其部署为节点应用程序。我遇到的问题让我感到沮丧。我根本无法安装 fibers 。编译过程一直报错,所以我放弃了。

反向代理IIS

我为自己解决这个问题的方法是在IIS上使用反向代理。

请参阅我在Meteor论坛上的帖子

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>
```

谢谢


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接