node.js - 当 Node 应用程序返回 4xx 时,IIS 返回 500

标签 node.js azure iis iisnode

我也在 iisnode github project 上问过这个问题

我通过 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 并将其发送到客户端。 401、409 等也是如此。它们都会导致发送 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>

无论如何,我无法让 IISnode 执行任何操作,只能从我的 Node 应用程序返回 200 秒。尝试让 IIS 为我的静态文件提供服务、启用 Node 检查器或任何更有趣的 IISNode 功能都会给我带来 500 的结果。不知道为什么,并且很想克服它!

类似的 StackOverflow 问题

this question几乎完全是我的问题。除此之外<httpErrors existingResponse="PassThrough" />对我不起作用。我觉得我的 IISNode 设置有一些更根本的错误,所以如果有人有任何可以尝试的想法,我会洗耳恭听。

最佳答案

由于某种原因,您的配置中的以下部分导致了此问题:

<staticContent>
    <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
    <mimeMap fileExtension=".ico" mimeType="image/x-icon" />
</staticContent>

作为解决方法,请删除此部分(如果可能)并重试。我将调查为什么此部分会导致此问题。

关于node.js - 当 Node 应用程序返回 4xx 时,IIS 返回 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22549579/

相关文章:

node.js - 主机 : localhost. 不在证书的替代名称中

c# - 无法在 Azure Active Directory 中添加 'Power BI Service' 以使用 Power BI API

asp.net - 黑客能否从 Azure 网站窃取 dll?

c# - 使用 HTTPS 配置 WCF 服务

javascript - 如何从 JavaScript 渲染的网页下载?

javascript - 仅将数据返回到数组中

javascript - node js 和 new 在使用 require 时

python - 如何为 Python 中的 document_client 对象发送的 Cosmos DB 查询设置连续 token ?

asp.net - IIS Web 应用程序子域

asp.net - 自动创建 IIS 6.0 网站