【发布时间】: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