在IIS

时间:2017-09-07 11:26:07

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

我尝试在Windows Server 2012 R2上部署节点应用,并在执行此操作时遇到问题。

服务器:Windows Server 2012 R2

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

2)来自https://www.iis.net/downloads/microsoft/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>
&#13;
&#13;
&#13;

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

我甚至尝试使用process.env.PORT而不是直接使用9025.那时我找不到404.

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

2 个答案:

答案 0 :(得分:1)

我找到了一个博客,并且我个人认为博客上提到的方法比IISNode好得多。请浏览以下博客。

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

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

答案 1 :(得分:1)

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