我有一个从Visual Studio 2017 Basic Azure Node.js Express Application生成的节点js express应用程序。我假设Azure部署所需的所有配置都在模板附带的Web.config文件中设置,但我在Azure发布后收到此错误:
iisnode在处理请求时遇到错误。 HRESULT:0x2 HTTP状态:500 HTTP subStatus:1002 HTTP原因: 内部服务器错误您收到此HTTP 200响应,因为 system.webServer/iisnode/@devErrorsEnabled配置设置为 '真'
除了node.exe进程的stdout和stderr的日志之外, 考虑使用调试和ETW跟踪来进一步诊断 问题
node.exe进程尚未向stderr或 iisnode无法捕获此信息。经常的原因是 iisnode模块无法创建要捕获的日志文件 node.exe的stdout和stderr输出。请检查身份 运行node.js应用程序的IIS应用程序池已读取 并将访问权限写入服务器所在的目录 node.js应用程序位于。或者,您可以禁用日志记录 通过设置system.webServer/iisnode/@loggingEnabled元素 web.config到' false'。
如果我发布应用程序而不修改任何内容,它运行良好,但是当我添加静态文件并添加相关模块时,它开始给我上面的错误。下面是我的web.config文件
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your Node.js application, please visit
http://go.microsoft.com/fwlink/?LinkId=290972
-->
<configuration>
<appSettings>
<!--
<add key="StorageAccountName" value="" />
<add key="StorageAccountKey" value="" />
<add key="ServiceBusNamespace" value="" />
<add key="ServiceBusIssuerName" value="" />
<add key="ServiceBusIssuerSecretKey" value="" />
-->
</appSettings>
<system.webServer>
<!-- mimeMap enables IIS to serve particular file types as specified by fileExtension. -->
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
<modules runAllManagedModulesForAllRequests="false" />
<!-- Web.Debug.config adds attributes to this to enable remote debugging when publishing in Debug configuration. -->
<iisnode watchedFiles="web.config;*.js;routes\*.js;views\*.pug"/>
<!-- Remote debugging (Azure Website with git deploy): Comment out iisnode above, and uncomment iisnode below. -->
<!--<iisnode watchedFiles="web.config;*.js;routes\*.js;views\*.pug"
loggingEnabled="true"
devErrorsEnabled="true"
nodeProcessCommandLine="node.exe --debug"/>-->
<!-- indicates that the server.js file is a Node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
<!-- Remote debugging (Azure Website with git deploy): Uncomment NtvsDebugProxy handler below.
Additionally copy Microsoft.NodejsTools.WebRole to 'bin' from the Remote Debug Proxy folder.-->
<!--<add name="NtvsDebugProxy" path="ntvs-debug-proxy/67499f58-9ba1-441d-b23f-6d860606ddb5" verb="*" resourceType="Unspecified"
type="Microsoft.NodejsTools.Debugger.WebSocketProxy, Microsoft.NodejsTools.WebRole"/>-->
</handlers>
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin" />
</hiddenSegments>
</requestFiltering>
</security>
<rewrite>
<rules>
<clear />
<!-- Remote debugging (Azure Website with git deploy): Uncomment the NtvsDebugProxy rule below. -->
<!--<rule name="NtvsDebugProxy" enabled="true" stopProcessing="true">
<match url="^ntvs-debug-proxy/.*"/>
</rule>-->
<!-- Don't interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
<rule name="app" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="iisnode.+" negate="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="app.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
<!-- Remote debugging (Azure Website with git deploy): uncomment system.web below -->
<!--<system.web>
<httpRuntime targetFramework="4.5"/>
<customErrors mode="Off"/>
</system.web>-->
</configuration>
答案 0 :(得分:1)
请确保您使用iisnode模块通过process.env.PORT
环境变量提供的监听地址。见Nodejs application returns error: iisnode encountered an error when processing the request HRESULT: 0x2 HTTP status: 500 HTTP subStatus: 1002。
要进一步排除故障,您可以启用stdout和stderr流的日志记录。关于如何操作,请参阅How to debug a Node.js web app in Azure App Service。