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

iisnode处理请求时遇到错误。

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

这是一个非常简单的节点/快速应用程序,我们不能在iisnode下运行。

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

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

我有与IISNode相同的问题,并花费了太多的时间来解决它。 我试图通过Windows资源pipe理器为不同的用户( IIS_USRSIUSRSEveryoneIIS AppPool/domainname )添加不同的权限,没有运气。

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

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