【问题标题】:Deploying Node App in IIS在 IIS 中部署节点应用程序
【发布时间】:2018-02-16 02:56:30
【问题描述】:

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

服务器:Windows Server 2012 R2

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

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

3) 将所有节点应用文件放置在某个位置。

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。当我尝试从其他机器(即http://servername:9025/)访问此 URL 时,出现以下错误:

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

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

【问题讨论】:

  • 请帮忙。我也在努力解决这个问题
  • @kamalav 请查看以下答案

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


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    我发现了一篇关于在窗口 install iisnode 上在 IIS 中安装和运行 nodejs 应用程序的博客: https://www.hanselman.com/blog/installing-and-running-nodejs-applications-within-iis-on-windows-are-you-mad

    【讨论】:

    • 请先添加一些与答案相关的步骤,然后尝试参考步骤。
    猜你喜欢
    • 2015-07-27
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 2015-12-19
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    • 2018-10-03
    相关资源
    最近更新 更多