• Gzip导致的页面载入出错和内容编码错误

    post by Holmesian / 2009-12-21 15:29 Monday

    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文件

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

     

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

     

     

    Chrome提示

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

    FireFox提示

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

     

     

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

     

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

     

     

    发表评论: