自定义HTTP错误页太小,导致显示默认友好错误页问题

一 . 问题描述:

  chrome 向服务器发送构造字符串,返回错误页面如下  

 1 <html>
 2     <head>
 3         <title>404 Not Found</title>
 4     </head>
 5     <body bgcolor="white">
 6         <center>
 7             <h1>404 Not Found</h1>
 8         </center>
 9         <hr>
10             <center>nginx/1.6.2</center>
11         </body>
12     </html>
13     <!-- a padding to disable MSIE and Chrome friendly error page -->
14     <!-- a padding to disable MSIE and Chrome friendly error page -->
15     <!-- a padding to disable MSIE and Chrome friendly error page -->
16     <!-- a padding to disable MSIE and Chrome friendly error page -->
17     <!-- a padding to disable MSIE and Chrome friendly error page -->
18     <!-- a padding to disable MSIE and Chrome friendly error page -->

  问题来了,最后六行注释是什么鬼?

二 . 为什么会出现这个问题

  IEbug #11289   always pad the error page with enough characters such that it is greater than 512 bytes, even after gzip compression.

  就是说在浏览器接收到的包比IE设置的阈值小的时候,就不会渲染显示这个包的内容,而是以IE 的内置错误页面来显示,比如联网错误.这样前端就不能正确判断错误类型.

三 . 解决.

  在Internet选项里面去掉 勾选 显示友好HTTP错误信息 选项.

*****

参考.

代码描述文件大小(阈值)
400 Bad Request > 512 bytes
403 Forbidden > 256 bytes
404 Not Found > 512 bytes
405 Method Not Allowed > 256 bytes
406 Not Acceptable > 512 bytes
408 Request Time-out > 512 bytes
409 Conflict > 512 bytes
410 Gone > 256 bytes
500 Internal Server Error > 512 bytes
501 Not Implemented > 512 bytes
505 HTTP Version Not Supported > 512 bytes

这些配置是在注册表里面的.

原文地址:https://www.cnblogs.com/liuyuxing/p/5110762.html