【问题标题】:iisnode encountered an error when processing the request. HTTP status: 500iisnode 在处理请求时遇到错误。 HTTP状态:500
【发布时间】:2015-10-20 22:51:26
【问题描述】:

iisnode在处理请求时遇到错误。

HRESULT:0x2 HTTP状态:500 HTTP 子状态:1001 HTTP 原因:内部服务器错误

这是一个相当简单的 node/express 应用程序,我们无法在 iisnode 下运行。

我们在 ETW 跟踪中看到错误,例如: 由于 iisnode 无法识别的原因,iisnode 请求处理失败 iisnode 无法建立到 node.exe 进程的命名管道连接

在节点输出中看到的最后一件事是: server Express http服务器监听端口\.\pipe\15524b7e-249a-4464-b41a-eddab028342e

我们在哪里可以找到正在发生的事情?

1) 通过在文件夹中的命令行键入 node server.js,节点应用程序可以正常工作。 2) javascript 中似乎没有“抛出”任何内容,我们有以下代码:

process.on('uncaughtException', function (err) {
    console.log(err);
    fs.writeFileSync("exception.txt", err, "utf8");
})

3) web.config如下:

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <system.webServer>
    <handlers>
      <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
      <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^server.js\/debug[\/]?" />
        </rule>

        <rule name="NodeLog">
          <action type="Rewrite" url="iisnode{REQUEST_URI}"/>
        </rule>

        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </rule>

        <!-- All other URLs are mapped to the node.js site entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="server.js"/>
        </rule>
      </rules>
    </rewrite>

    <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
          <add segment="node_modules"/>
        </hiddenSegments>
      </requestFiltering>
    </security>

    <!-- Make sure error responses are left untouched -->
    <httpErrors existingResponse="PassThrough" />

    <!--
      You can control how Node is hosted within IIS using the following options:
        * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
        * node_env: will be propagated to node as NODE_ENV environment variable
        * debuggingEnabled - controls whether the built-in debugger is enabled

      See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
    -->
    <!--<iisnode watchedFiles="web.config;*.js"/>-->
    <defaultDocument enabled="true">
      <files>
        <add value="server.js" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>

server.js 非常简单:

var fs = require('fs');
var express = require('express');
var path = require('path');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var methodOverride = require('method-override'); // Lets you use HTTP verbs such as PUT or DELETE in places where the client doesn't support it.

var routes = require('./routes/index');

var http = require('http');
var https = require('https');
var options = {
    pfx: fs.readFileSync(path.join(__dirname, 'sslcert') + '/web.local.pfx'),
    passphrase: ''
}

var app = express();

//app.engine("ejs", ejsEngine); // templating engine

// must set up environment before controllers establish routes

// all environments
// set default port if not set
//app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));

// opt into services
app.use(express.static(path.join(__dirname, 'public')));

app.use(morgan('dev'));
app.use(bodyParser.urlencoded({ extended: false }));

app.use(bodyParser.json());
app.use(methodOverride());

/* api access */
app.get('/api', function (req, res) {
    res.send('api is up and running');
});

//app.get('*', function (req, res) {
//    res.render('index.html');
//});

var port = process.env.PORT || 3000;

// start the web server
http.createServer(app).listen(app.get(port), function () {
//http.createServer(app).listen(2025, function () {
    console.log('server', 'Express http server listening on port' + port);
});

https.createServer(options, app).listen(8443, function () { 
    console.log('server', 'Express https server listening on port 8443');
});

module.exports = app;

【问题讨论】:

  • 当我们第一次决定在我们的 Windows 服务器上运行节点应用程序时,我们尝试使用 iisnode,但是最终选择使用反向代理并将节点服务器作为服务运行以避免不得不处理 iis 与我们的节点进程的集成。
  • 就您的问题而言,它看起来更像是 iisnode 问题而不是节点问题,除非您的节点应用程序正在退出并且以某种方式缺少 uncaughtException 处理程序。
  • 你是如何启动你的服务器的? (我在找javascript代码,比如if (require.main === module) { start(); }
  • 1001 在这种情况下意味着:“递归太深;堆栈溢出。”您可以使用net helpmsg 1001 自己获取该消息,尽管该消息并没有太大帮助。
  • @Kevin B 查看我发布的 server.js。没什么大不了的。

标签: node.js iis express iisnode


【解决方案1】:

我在IISNode 上遇到了同样的问题,并且花了太多时间试图修复它。我尝试通过 Windows 资源管理器为不同的用户(IIS_USRSIUSRSEveryoneIIS AppPool/domainname)添加不同的权限,但没有成功。

我终于在setupexamples.bat 脚本中找到了解决方案,并提供了iisnode 示例。在包含您的应用代码的文件夹上简单地运行以下脚本:

icacls (folder_name) /grant IIS_IUSRS:(OI)(CI)F /t

【讨论】:

  • 我运行 setupexamples.bat 但我不知道现在该做什么,该代码执行错误
  • 我没有运行实际的 setupexamples.bat 脚本;我使用部分脚本作为示例如何设置正确的权限。只需在包含您的应用程序的文件夹上运行上述命令即可。
  • 我尝试了web.config的所有组合,但没有任何效果,我连续花了4天解决这个问题,仍然没有机会找到解决方案
  • 您是否尝试通过 Windows 资源管理器为包含应用程序的文件夹设置权限(递归)?我通常将权限设置为每个人的完全访问权限,然后我运行上面的 icalcs 命令
猜你喜欢
  • 2018-08-03
  • 2014-07-24
  • 1970-01-01
  • 2015-08-28
  • 1970-01-01
  • 2020-02-02
  • 2022-01-22
  • 2015-12-04
相关资源
最近更新 更多