【发布时间】:2017-07-27 11:51:37
【问题描述】:
我有一个非常简单的 nodejs https 服务器,我正在尝试使用 iisnode,但似乎节点进程没有启动,所以当我尝试导航到它时出现 500 错误.
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const fs = require('fs');
const cors = require('cors');
var https = require('https');
app.use(bodyParser.json());
app.use(cors());
app.get('/', function (req, res) {
res.send('Hello World!')
});
var secureServer = https.createServer({
key: fs.readFileSync('private.key'),
cert: fs.readFileSync('certificate.pem')
}, app).listen(process.env.PORT || 3443, function () {
console.log('Secure Server listening on port 3443');
});
如果我执行 node server.js,此应用程序启动正常,但是当我尝试依赖 setupsamples.bat 脚本设置的节点虚拟目录时,它似乎不起作用。我的 Web.config 也是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<modules>
<remove name="MyAuthModule" />
</modules>
<security>
<authorization>
<add accessType="Allow" users="?" />
</authorization>
</security>
<rewrite>
<rules>
<rule name="mcServer">
<match url="mcServer/*" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
MyAuthModule 是在我的环境中为我设置的自定义身份验证模块,因此如果我没有删除语句,我会收到有关该模块不存在的错误。
我将server.js、上面显示的Web.config 和证书文件放置在iisnode/www 目录中的mcServer 目录中,该目录是通过运行setupsample.bat 脚本创建的。当我导航到 https://myUrl/node/mcServer 时,我收到 500 错误,但如果我导航到 https://myUrl/node,它会显示可用的不同应用程序,就像我说的,节点进程没有运行,所以我认为这是我得到的 500 错误。
还需要注意的是,我安装了 url 重写模块,所以这不应该是问题,helloworld/readme.htm,但我再次假设这是因为节点尚未启动。
我一定是在做一些完全愚蠢的事情,但我想不通。
【问题讨论】: