简体   繁体   中英

iisnode encountered an error when processing the request. HTTP status: 500

iisnode encountered an error when processing the request.

HRESULT: 0x2 HTTP status: 500 HTTP subStatus: 1001 HTTP reason: Internal Server Error

This is a fairly simple node/express application which we cannot get to run under iisnode.

We are seeing errors in the ETW trace such as: iisnode request processing failed for reasons unrecognized by iisnode iisnode was unable to establish named pipe connection to the node.exe process

The last thing seen in the node output is: server Express http server listening on port \\.\\pipe\\15524b7e-249a-4464-b41a-eddab028342e

Where can we look to find out what is happening?

1) the node application works correctly from the command line in the folder, by typing node server.js. 2) There is seemingly nothing "thrown" in the javascript, we have this code:

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

3) the web.config is as follows:

<?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>

The server.js is pretty simple:

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;

I had the same issue with IISNode and spent far too much time trying to fix it. I tried adding different permissions for different users ( IIS_USRS , IUSRS , Everyone , IIS AppPool/domainname ) through Windows explorer with no luck.

I finally found the solution in the setupexamples.bat script, provided with the iisnode examples. Simple run the following script on the folder containing your app code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM