处理请求时,iisnode遇到错误。 HTTP状态:500

时间:2015-07-29 19:16:00

标签: node.js iis express iisnode

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

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

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

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

节点输出中看到的最后一件事是: 服务器快速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;

1 个答案:

答案 0 :(得分:2)

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

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

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