当Node应用程序返回一个4xx时,IIS返回500
我也曾经在iisnode github项目上问过这个问题
我通过Windows Azure网站使用IISNode。
如果我的Node应用程序返回一个2xx状态码(200,201等),那么一切都很好,并按预期工作。
如果我的Node应用程序返回一个4xx状态码,例如: response.send(404, "not found")
(我正在使用Restify),那么我得到一个500发送到客户端,身体只是“页面无法显示因为发生了内部服务器错误。“
如果我做azure site log tail <sitename>
,那么当500被发送到客户端时,日志包含404的HTML。
... <body> <div id="content"> <div class="content-container"> <h3>HTTP Error 404.0 - Not Found</h3> <h4>The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.</h4> </div> ...
我真的只是希望IISNode / IIS采取我的404并将其发送到客户端。 401s,409s等也是如此,它们全部导致500发送。
我已经尝试过<customErrors mode="off" />
和<httpErrors existingResponse="passThrough" />
在我的web.config中无济于事。 这是我的web.config现在:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.web> <customErrors mode="off" /> </system.web> <system.webServer> <httpErrors existingResponse="PassThrough" /> <staticContent> <mimeMap fileExtension=".svg" mimeType="image/svg+xml" /> <mimeMap fileExtension=".ico" mimeType="image/x-icon" /> </staticContent> <handlers> <add name="iisnode" path="server.js" verb="*" modules="iisnode"/> </handlers> <rewrite> <rules> <rule name="DynamicContent"> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/> </conditions> <action type="Rewrite" url="server.js"/> <match url="/*" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
对于它的价值,我不能让IIS节点做任何事情,但从我的节点应用程序返回200。 试图让IIS服务我的静态文件,启用节点检查器,或任何更有趣的IISNodefunction,导致我500。 不知道为什么,并希望通过它!
类似的StackOverflow问题
这个问题几乎是我的问题。 除了<httpErrors existingResponse="PassThrough" />
不适用于我。 我感觉我的IISNode设置有一些更根本性的错误,所以如果有人有任何想法尝试我的耳朵。
出于某种原因,您的configuration中的以下部分导致此问题:
<staticContent> <mimeMap fileExtension=".svg" mimeType="image/svg+xml" /> <mimeMap fileExtension=".ico" mimeType="image/x-icon" /> </staticContent>
作为解决方法,请尽可能删除此部分,然后重试。 我将调查为什么这部分是造成这个问题。
正如Ranjith所指出的, staticContent
部分是冲突的原因。 我只是发现你可以限制location
条目中的那些条目,所以你可以根据需要获得所有的IISNode,并且仍然提供静态内容。 我的web.config现在看起来像这样:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.web> <customErrors mode="off" /> </system.web> <system.webServer> <handlers> <add name="iisnode" path="server.js" verb="*" modules="iisnode"/> </handlers> <rewrite> <rules> <rule name="Redirect to https" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" appendQueryString="true" /> </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> <httpErrors existingResponse="PassThrough" /> </system.webServer> <location path="public/fonts"> <system.webServer> <staticContent> <mimeMap fileExtension=".woff" mimeType="application/font-woff" /> </staticContent> </system.webServer> </location> </configuration>
最后添加的location
条目在500个左右和静态内容冲突。
我从Azure / IIS返回完全相同的… 500错误页面。 我使用了Azure自动生成的web.config作为基础,然后添加了<customErrors mode="off" />
和<httpErrors existingResponse="PassThrough" />
。 我也删除了默认的staticContent节点。 没有任何工作。
下面是我上传到Azure的web.config。 什么在这里导致IIS / iisnode返回一个500错误页面而不是简单的文本错误消息我有节点/快递返回到客户端?
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.web> <customErrors mode="off" /> </system.web> <system.webServer> <httpErrors existingResponse="PassThrough" /> <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="DynamicContent"> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/> </conditions> <action type="Rewrite" url="server.js"/> </rule> </rules> </rewrite> </system.webServer> </configuration>
这适用于我:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <handlers> <add name="iisnode" path="app.js" verb="*" modules="iisnode"/> </handlers> <rewrite> <rules> <rule name="DynamicContent"> <match url="/*" /> <action type="Rewrite" url="app.js"/> </rule> </rules> </rewrite> </system.webServer> </configuration>