node.js - 在 IIS 中部署 Node 应用程序

标签 node.js iis windows-server-2012-r2 iisnode

我正在尝试在 Windows Server 2012 R2 上部署 Node 应用程序,但在执行相同操作时遇到问题。

服务器:Windows Server 2012 R2

1) 我已经从 https://github.com/tjanczuk/iisnode/wiki/iisnode-releases 安装了 IIS Node [iisnode for iis 7/8(x64)]

2) 从 https://www.iis.net/downloads/microsoft/url-rewrite 安装 URL 重写模块

3)将所有 Node 应用程序文件放置在某个位置。

4) 从该项目目录中,发出 npm install 来安装所需的软件包。

server.js

require('rootpath')();
var express = require('express');
var app = express();
var cors = require('cors');
var bodyParser = require('body-parser');
var config = require('config.json');


app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

 
// routes
app.use('/users',  require('./services/user.service'));
app.use('/tools',  require('./services/tool.service'));
app.use('/orders', require('./services/order.service'));
app.use('/util',   require('./services/util.service'));

// start server
var port = 9025;


var server = app.listen(port, function () {
    console.log('Server listening on port ' + port);
});

web.config

<configuration>
   <system.webServer>

     <!-- indicates that the server.js file is a node.js application 
     to be handled by the iisnode module -->

     <handlers>
       <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
     </handlers>

     <!-- use URL rewriting to redirect the entire branch of the URL namespace
     to server.js node.js application; for example, the following URLs will 
     all be handled by server.js:
     
         
     -->

     <rewrite>
       <rules>
         <rule name="rewriteRule">
           <match url="/*" />
           <action type="Rewrite" url="server.js" />
         </rule>
       </rules>
     </rewrite>

     <!-- exclude node_modules directory and subdirectories from serving
     by IIS since these are implementation details of node.js applications -->
     
     <security>
       <requestFiltering>
         <hiddenSegments>
           <add segment="node_modules" />
         </hiddenSegments>
       </requestFiltering>
     </security>    
     
   </system.webServer>
 </configuration>

然后,我使用 IIS 创建了一个引用这一特定项目文件夹的网站。创建网站时提供的端口号为 9025。当我尝试从其他计算机访问此 URL 时,即 http://servername:9025/我收到以下错误: enter image description here

我什至尝试使用 process.env.PORT 而不是直接使用 9025。当时我得到了 404 not find。

请让我知道我做错了什么?

最佳答案

我找到了一篇博客,个人觉得博客上提到的方式比IISNode好很多。请浏览以下博客。

Hosting a Node.js application on Windows with IIS as reverse proxy

我知道现在回答这个问题已经太晚了,但还没人回答,所以我回答了。我希望它能帮助其他人。

关于node.js - 在 IIS 中部署 Node 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46095173/

相关文章:

powershell - 工作组环境中 Server 2012 及更高版本上的 RemoteApps

javascript - Node.js Google-云存储上传目的地规范

javascript - 如何从nodejs访问Angular Js数据

iPhone SSL 客户端证书不起作用

c# - ASP.Net Session 数据在页面之间丢失

C# smtpclient.send 开发速度非常慢,但生产速度很快

Windows 上的 git shell 报告 "sh.exe has stopped working (APPCRASH)"

node.js - 如果其中任何一个任务出错,async.parallel 是否仍会在所有任务完成后调用最终回调?

node.js - 与 AZURE 服务器建立连接时,在 TCP.onStreamRead 错误处读取 ECONNRESET

.net - 如何在 Windows 2012 R2 Core 上的代理后面安装 Chocolatey 软件包?