-->

Permissions and request with iisnode

2019-08-03 19:40发布

问题:

I run my Node.js app and I got a heavy error

iisnode encountered an error when processing the request.

HRESULT: 0x2
HTTP status: 500
HTTP subStatus: 1002
HTTP reason: Internal Server Error
You are receiving this HTTP 200 response because system.webServer/iisnode/@devErrorsEnabled configuration setting is 'true'.

In addition to the log of stdout and stderr of the node.exe process, consider using debugging and ETW traces to further diagnose the problem.

The node.exe process has not written any information to stderr or iisnode was unable to capture this information. Frequent reason is that the iisnode module is unable to create a log file to capture stdout and stderr output from node.exe. Please check that the identity of the IIS application pool running the node.js application has read and write access permissions to the directory on the server where the node.js application is located. Alternatively you can disable logging by setting system.webServer/iisnode/@loggingEnabled element of web.config to 'false'.

Some say that error is from env.Port others say that is from webconfig that I need to set to server.js ,I set it already ,even if I delete it I got the same errors.

I tried with iis client to set permissions

In 3 days I can't figure out what I did wrong,I tried with and without web.cofig. Am I missing something ? Also the connection to MongoDB is set with the string provided by Azure portal.

回答1:

I am able to reproduce the exact same error.

Here is my server.js:

const express = require('express')
const app = express()

app.get('/', function (req, res) {
  res.send('Hello World!')
})

app.listen(3000)

In web.config, I have this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.webServer>        
        <webSocket enabled="false" />

        <handlers>
            <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
        </handlers>

        <rewrite>
            <rules>
                <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="^server.js\/debug[\/]?" />
                </rule>
                <rule name="StaticContent">
                    <action type="Rewrite" url="public{REQUEST_URI}" />
                </rule>
                <rule name="DynamicContent">
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
                    </conditions>
                    <action type="Rewrite" url="server.js" />
                </rule>
            </rules>
        </rewrite>

        <security>
            <requestFiltering>
                <hiddenSegments>
                    <remove segment="bin" />
                </hiddenSegments>
            </requestFiltering>
        </security>

        <httpErrors existingResponse="PassThrough" />

        <iisnode 
            watchedFiles="web.config;*.js" 
            node_env="%node_env%" 
            loggingEnabled="true" 
            logDirectory="iisnode" 
            debuggingEnabled="true" 
            maxLogFileSizeInKB="1048" 
            maxLogFiles="50" 
            devErrorsEnabled="true" />
    </system.webServer>
</configuration>

With these configurations, I can visit https://{mysitename}.scm.azurewebsites.net/api/vfs/site/wwwroot/iisnode/index.html to see the detailed error.

After changing app.listen(3000) to app.listen(process.env.PORT || 3000), I got it to work.

More on this:

Nodejs application returns error: iisnode encountered an error when processing the request HRESULT: 0x2 HTTP status: 500 HTTP subStatus: 1002



回答2:

Hope this will help. I also get this issue and i had to put lot of time on investigating how to solve, did all the permission related changes etc... but finally i thought to give a try by giving the bin/www path instead server.js (In my case it's app.js) and it worked :).

My web.config file looks like below

<handlers>
    <add name="iisnode" path="bin/www" verb="*" modules="iisnode" />
</handlers>

<rewrite>
    <rules>
        <rule name="myapp">
            <match url="/*" />
            <action type="Rewrite" url="bin/www" />
        </rule>
    </rules>
</rewrite>