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中的 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然后注册它。
- 互操作性Azure服务总线消息队列消息
- 使用docker镜像的Azure Linux应用程序服务中的Mongo连接错误
- 通过Git部署简单的SPA到Azure
- 在服务器端的Azure移动服务令牌上解密或validation签名
- Node.js azure-storage TableService没有方法
- 使用节点sdk进行Azurevalidation时出错:
- 设置根path以在Azure上提供index.html(IIS Web服务器)
- 尝试通过节点createBlockBlobFromStream()将Blob上载到Azure存储时发生“RequestBodyTooLarge”
- 运行在Azure上的express.js中的multipart / form-data错误