iisnode没有启动节点进程

时间:2017-07-27 00:53:52

标签: node.js iis-8.5 iisnode

我有一个非常简单的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');
});

如果我做节点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和证书文件放在mcServer目录中自己的iisnode/www目录中,该目录是通过运行setupsample.bat脚本创建的。当我导航到https://myUrl/node/mcServer时,我收到500错误,但如果我导航到https://myUrl/node,它会显示可用的不同应用程序,就像我说的那样,节点进程没有运行,所以我认为这是我得到的500错误的一部分。

我还注意到我安装了url rewrite模块,因此不应该是问题,helloworld/readme.htm,但我再次假设这是因为节点尚未启动。< / p>

我必须做一些完全愚蠢的事情,但我无法理解。

1 个答案:

答案 0 :(得分:0)

有几件事我错了:

  • 我尝试使用npm link <module_name>,但这显然不适用于IIS,所以我为所有需要的模块npm install做了
  • 我的match url应该是/*,而不是mcServer/*
  • 在我的server.js文件中,我需要在app.get前添加app.get('/mcServer/'