【发布时间】:2013-02-15 04:01:13
【问题描述】:
我正在使用 Windows Azure 网站来托管 node.js 应用程序。到目前为止,除了我的自定义错误之外,一切都很好。在我的节点应用程序中,我有一个错误处理程序,可以在我的本地机器上呈现自定义 404 和自定义 500 错误页面。但是,一旦我发布到 azure,当我将 statusCode 设置为 200 以外的任何值时,它都会覆盖响应。
如果我没有将 500 或 404 statusCode 传递给响应,则不会发生这种情况,但我确实希望将状态代码发送到浏览器。在本地我得到我的自定义错误页面就好了:
但是,在 azure 网站上它只返回一行文本:
由于发生内部服务器错误,页面无法显示。
我尝试创建自己的 web.config 以覆盖禁用自定义错误的默认配置,但这似乎没有任何效果。这是我的 web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<customErrors mode="off" />
</system.web>
<system.webServer>
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<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="app.js"/>
</rule>
</rules>
</rewrite>
<iisnode
debuggingEnabled="true"
devErrorsEnabled="true"
debuggerPathSegment="debug"
nodeProcessCommandLine=""%programfiles(x86)%\nodejs\node.exe""
logDirectory="..\..\LogFiles\nodejs"
watchedFiles="*.js;iisnode.yml;node_modules\*;views\*.jade;views\*.ejb;routes\*.js" />
</system.webServer>
</configuration>
我不确定iisnode(将请求路由到node.js 的iis 扩展)是否负责覆盖我的错误页面,或者iis 本身是否负责。有什么建议吗?
【问题讨论】:
-
这对我不起作用,最终的原因是我的 web.config 中有一个
<staticContent>部分。为我删除修复它:stackoverflow.com/questions/22549579/… -
感谢@MattGreer 提供的信息。是您自己添加了
<staticContent>元素还是 Azure 网站默认 web.config 中的新元素?如果它是默认 web.config 的一部分,那么我想更新此答案以反映您的更正。 -
我自己添加它是为了让 IIS 为 SVG 提供服务(默认情况下不这样做)
标签: node.js azure web-config iisnode