Azure网站上的Node.js 404错误

我正在Azure网站上运行Node.js 0.10.15&Express应用程序,并且在有人input无效URL时发生404错误。 我得到通用The page cannot be displayed because an internal server error has occurred. 我尝试访问无效的url时出错。

以下是发送404页面的app.js文件末尾的代码:

 app.get('/*', function(req, res) { res.status(404).sendfile('public/404.html'); }); 

奇怪的是,当我在本地运行我的服务器时,Express似乎正在正确地将404与HTML文件一起发送,但是当它在Azure上运行时,它会窒息并且不会给我一个有用的错误。 日志显示请求按预期工作:

 [Thu, 24 Oct 2013 01:10:39 GMT] "GET /asdfsadf HTTP/1.1" 404 - "-" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36" 

我怀疑这个问题不知何故在于我的web.config文件:

 <?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <httpErrors existingResponse="PassThrough" /> <staticContent> <mimeMap fileExtension=".svg" mimeType="image/svg+xml" /> <mimeMap fileExtension=".woff" mimeType="application/x-woff" /> <mimeMap fileExtension=".ttf" mimeType="application/x-woff" /> </staticContent> <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> 

我也打开了iisnode.yml文件的日志logging:

 loggingEnabled: true devErrorsEnabled: true 

另外,你可以在GitHub上看到我的开发工作分支

查看Windows Azure网站正在覆盖我的node.js应用程序和https://github.com/tjanczuk/iisnode/issues/295中&#x7684; 404和500错误页面

两者都为我工作。 我没有任何Web.config为我的快速应用程序,这就是我使用的:

 <configuration> <system.webServer> <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"/> </rule> </rules> </rewrite> <httpErrors existingResponse="PassThrough"/> </system.webServer> </configuration> 

当我遇到这个问题,帮助我

 <staticContent> <remove fileExtension=".svg" /> <mimeMap fileExtension=".svg" mimeType="image/svg+xml" /> <remove fileExtension=".woff" /> <mimeMap fileExtension=".woff" mimeType="application/application/font-woff" /> <remove fileExtension=".ttf" /> <mimeMap fileExtension=".ttf" mimeType="application/x-font-truetype" /> <remove fileExtension=".otf" /> <mimeMap fileExtension=".otf" mimeType="application/x-font-opentype" /> </staticContent> 

所以在声明一个mimeMap之前,需要确保mimeType没有默认注册,这就是为什么你可以删除mimeType然后注册它。