windows 你可以在 IIS 中使用 node.js 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5546326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:33:13  来源:igfitidea点击:

Can you use node.js with IIS?

windowsiisnode.js

提问by Rod Johnson

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?

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

采纳答案by amazedsaint

Walkthrough for setting up Windows + IIS + Node.js + Mongodb to build a quick todo application

设置 Windows + IIS + Node.js + Mongodb 以构建快速待办事项应用程序的演练

http://www.amazedsaint.com/2011/09/creating-10-minute-todo-listing-app-on.html

http://www.amazedsaint.com/2011/09/creating-10-minute-todo-listing-app-on.html

回答by JensJ

Sure you can, check out the IISNode Project.

当然可以,请查看IISNode 项目

回答by Andrew Marshall

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:

您可以在 Windows 上安装 Node.js,但它是它自己的服务器,因此除非您使用 IIS 作为它的代理,否则根本不需要 IIS。但请注意,以下引用自Node.js 的安装说明

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

[Windows] 构建都不是令人满意的稳定,但可以运行一些东西。

回答by Tracker1

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

您基本上有两条路线可以通过 IIS 运行 Node.js 应用程序。

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.

如果您将整个应用程序专用于 Node.js 并且只需要面向公众的端点来处理您现有的 IIS 应用程序,我建议使用 ARR 来路由整个站点。我正在为几个项目执行此操作,并且效果很好。

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.

老实说,我不喜欢 IISNode,因为看起来您在节点代码与 IIS 中创建了外来端点。它有效,如果您特别针对 Azure,它可能是您的最佳选择。如果您必须将其硬塞到现有的 .Net 应用程序中,它也可能是最佳选择。

回答by johans

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.

我一直在 Windows 上使用带有 Cygwin 的 Node 并且几乎没有问题。您可以使用 IIS 在默认端口 80 上提供服务,并在不同端口上运行您的 Node 应用程序。

If you want to proxy then most are using Nginx.

如果你想代理,那么大多数都在使用 Nginx。

回答by yojimbo87

You can buildnode.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.

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

回答by Aaron C

I wanted to make it as easy as possible.

我想让它尽可能简单。

Issues with iisnode

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 fibersto install at all. compilation process kept trowing errors, so I gave up.

  1. 我安装了 iisnode 并毫无问题地运行了示例,但是...

  2. 我尝试使用 iisnode 在 IIS 上部署它,但我必须捆绑我的流星应用程序,然后将其部署为节点应用程序。我遇到的问题使我气馁。我根本无法fibers安装。编译过程不断出现错误,所以我放弃了。

Reverse Proxy IIS

反向代理 IIS

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

我为解决这个问题所做的是在 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/nor http://localhost:3100/will give us an error Unknown path.

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

Turns out that on my IIS config, I have to specify the http://localhost:3100/n/todosas 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>
```

我最后的 web.config 条目是:

我做了同样的事情,但是,我在 IIS 上使用反向代理来使用域上的子文件夹的方式让我感到厌烦。

我不知道通过使用 ROOT_URL 我们可以指定子路径。

例如,如果我在我的流星应用程序文件夹中运行以下命令:

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

我将能够在 访问我的应用程序http://localhost:3100/n/todos,注意我省略了尾随/. 如果我们尝试浏览该地址http://localhost:3100/nhttp://localhost:3100/会给我们一个错误Unknown path

所以,当我第一次设置反向代理时,我Unknown Path每次都收到错误。

事实证明,在我的 IIS 配置中,我必须将 指定 http://localhost:3100/n/todos为操作的 url 值,请注意末尾的“n/todos”

所以我的重写规则最终是这样的:[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

谢谢