我正在尝试在 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/我收到以下错误:
我什至尝试使用 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/