【问题标题】:iisnode not starting node processiisnode没有启动节点进程
【发布时间】: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,但我再次假设这是因为节点尚未启动。

我一定是在做一些完全愚蠢的事情,但我想不通。

【问题讨论】:

    标签: node.js iis-8.5 iisnode


    【解决方案1】:

    我做错了几件事:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-31
      • 1970-01-01
      • 1970-01-01
      • 2019-07-18
      • 1970-01-01
      • 2020-07-07
      相关资源
      最近更新 更多