Gzip导致页面和编码错误

注意:本文最后更新于 2350 天前,有关的内容可能已经发生变化,请参考使用。

Blog.ecjtu.net的问题已经出了好几天了,一直没有时间仔细去研究。具体问题体现在某些用户的博客首页无法打开,而大部分有可以正常打开,最近这两天听博客管理员说报告类似错误的用户越来越多所以今天就仔细的找了一下原因。

博客系统使用的是SupeSite/X-Space由Ucenter和论坛整合,服务器是FreeBSD,前端Nginx,后端Apache跑php(暂时这样,准备年后换FastCGI)。

用IE6访问全站正常,用非IE6的浏览器,如IE7、IE8、FireFox、Chrome等浏览器打开时都无法打开部分用户的首页,提示内容如下

FireFox无法访问,提示错误

Chrome无法访问,提示错误

IE可以访问

一开始以为是Rewrite的问题,换了好几种Rewrite的方法,问题依旧。 后来注意到所有的Rewrite都会重定向都会回到一个文件iframe.php上,而且所有无法访问的用户的首页几乎都是形同这种http://blog.ecjtu.net/iframe.php?uid=92649样式。接着开始仔细分析这个iframe.php文件。

以下是iframe.php文件内容:

      1. <?php 
      2. /*
      3. [SupeSite/X-Space] (C)2001-2006 Comsenz Inc.
      4.   5. $RCSfile: iframe.php,v $
      6. $Revision: 1.3 $
      7. $Date: 2007/08/01 08:11:21 $
      8. */
      9. include_once('./include/main.inc.php'); 
      10. include_once(S_ROOT.'./language/batch.lang.php'); 
      11. dbconnect(); 
      12. $_GET['uid'] = intval($_GET['uid']); 
      13. $reauthcode = md5($_SCONFIG['sitekey'].$_GET['uid']); 
      14. $s_url = S_URL; 
      15. if($_GET['passpage'] == 1) { 
      16. echo '<script language="javascript" type="text/javascript">location.href="'.S_URL.'/index.php?uid-'.$_GET['uid'].'-noframe-1";</script>'; 
      17. exit; 
      18. }else { 
      19. $newurl = S_URL."/batch.common.php?action=musicpasspage&uid=$_GET[uid]&hash=$reauthcode"; 
      20. } 
      21. if(emptyempty($newurl)) { 
      22. $display = 'none'; 
      23. } else { 
      24. $display = ''; 
      25. } 
      26. $space = getuserspace($_GET['uid']); 
      27. print <<<EOF 
      28. <html> 
      29. <head> 
      30. <meta http-equiv="Content-Type" content="text/html; charset=$_SCONFIG[charset];"> 
      31. <title>$space[spacename] Power by X-Space</title> 
      32. <script> 
      33. function framebutton(){ 
      34. var obj = document.getElementById('navigation'); 
      35. var musicobj = document.getElementById('topFrame'); 
      36. var frameswitch = document.getElementById('frameswitch'); 
      37. var switchbar = document.getElementById('switchbar'); 
      38. if(obj.style.width == '1px'){ 
      39. obj.style.width = '192px'; 
      40. musicobj.style.width = '192px'; 
      41. switchbar.style.left = '192px'; 
      42. frameswitch.style.backgroundPosition = '0'; 
      43. frameswitch.src = '$s_url/images/flashplayer/btn_hide.jpg'; 
      44. }else{ 
      45. obj.style.width = '1px'; 
      46. musicobj.style.width = '1px'; 
      47. switchbar.style.left = '1px'; 
      48. frameswitch.style.backgroundPosition = '-11'; 
      49. frameswitch.src = '$s_url/images/flashplayer/btn_show.jpg'; 
      50. } 
      51. } 
      52.   53. if(top != self) { 
      54. top.location = self.location; 
      55. } 
      56. </script> 
      57. </head> 
      58. <body style="height: 100%; margin: 0; padding: 0;" scroll="no"> 
      59. <table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0"> 
      60. <tr> 
      61. <td id="navigation" style="width:1px; height:200px; url($s_url/images/flashplayer/bg_framebottom.jpg) no-repeat left bottom; vertical-align:top; "> 
      62. <iframe src="$newurl" frameborder="0" scrolling="no" style="width:1px; height:100% ;" name="topFrame" id="topFrame"></iframe> 
      63. </td> 
      64. <td style="height: 100%;width: 100%;"> 
      65. <table id="switchbar" width="14" height="100%" cellspacing="0" cellpadding="0" border="0" style="position: absolute; left: 1px; background-repeat: repeat-y; background-position: -192px; repeat-y left center;"> 
      66. <tbody> 
      67. <tr> 
      68. <td onClick="framebutton()" style="display:$display"><img id="frameswitch" border="0" src="images/flashplayer/btn_show.jpg" style="background-position: 0pt 50%;"/></a></td> 
      69. </tr> 
      70. </tbody> 
      71. </table> 
      72. <iframe style="height: 100%; width: 100%; " src="$s_url/index.php?uid-$_GET[uid]-noframe-1" name="mainFrame" frameborder="0" scrolling="yes"></iframe> 
      73. </td> 
      74. </tr> 
      75. </table> 
      76. </body> 
      77. </html> 
      78. EOF; 
      79. ?> 

但是经过一番分析和测试之后基本可以确定这个文件是没有问题的,无意之中注意到Firefox和Chrome的错误提示:

Chrome提示

错误 330 (net::ERR_CONTENT_DECODING_FAILED):未知错误。

FireFox提示

无法显示您尝试查看的页面,因为它使用了无效或者不支持的压缩格式。

因为没有读过这个x-space的代码 所以不好百分之百确定原因 不过就目前所有的现象表明,这个可能性最高的还是这Iframe.php文件,尤其是最后那一个iframe标签。单间地说就是客户端接收到的内容是部分Gzip压缩,所以符合标准像FireFox,Chrome这样符合标准的浏览器就会提示内容有错误不可靠。但是IE6啥也不管:能解压的就解压没压缩的就不解压 所以就能看。至于为什么部分用户的博客首页可以打开而另一部分不可以,那就要关注一个细节:所有不能打开的用户的首页都加入了在线音乐播放器这个功能,不出意外的话问题就应该出在这个播放器代码上了。

猜测得差不多了,具体原因下次技术部开会再探讨吧。


「倘若有所帮助,不妨酌情赞赏!」

Holmesian

感谢您的支持!

使用微信扫描二维码完成支付


相关文章

发表新评论