apache / incubator-pagespeed-ngx

Automatic PageSpeed optimization module for Nginx
http://ngxpagespeed.com/
Apache License 2.0
4.36k stars 363 forks source link

Only half a website page loading, white screens etc. #933

Closed goregrish closed 9 years ago

goregrish commented 9 years ago

Hi, I'm trying this out with a video script, not having much luck with the index page in particular. Not entirely sure how to debug this properly...

If I load the index page of the website with pagespeed enabled it cuts off the page near the bottom, while working its way through loading a grid of images using bootstrap and smarty .tpl files. The website only works with pagespeed turned off, just disabling the filters and the like has no effect.

The login page just returns a white screen.

My images loop, after showing 20 images it just decides to cut off abruptly (titles, alt's and URL's removed for privacy):

....

<div class="col-md-2 portfolio-item desktop-only">
<a href="">
<img class="lazy img-responsive desktop-only"
src="/media/videos/tmb/57/238x179x1.jpg.pagespeed.ic.fJ0Tkwm9U_.webp" 
alt="the alt"  
id="rotate_57_20_recent" data-original="/media/videos/tmb/57/1.jpg" 
title="this title works fine" width="238" height="179"/></a>
</div>

<div class="col-md-2 portfolio-item desktop-only">
<a href="">
<img class="lazy img-responsive desktop-only"
src="/media/videos/tmb/57/238x179x1.jpg.pagespeed.ic.fJ0Tkwm9U_.webp" 
alt="the alt"  
id="rotate_57_20_recent" data-original="/media/videos/tmb/57/1.jpg" 
title="this title works fine" width="238" height="179"/></a>
</div>

<div class="col-md-2 portfolio-item desktop-only">
<a href="">
<img class="lazy img-responsive desktop-only" 
src="/media/videos/tmb/57/238x179x1.jpg.pagespeed.ic.fJ0Tkwm9U_.webp" 
alt="the alt" 
id="rotate_56_20_recent" data- original="/media/videos/tmb/56/1.jpg" 
title="the website just cuts off here and ends the page, no closing tags, footer, nothing...

I have this in nginx conf

 # enable ngx_pagespeed
 pagespeed on;
 pagespeed FileCachePath /var/ngx_pagespeed_cache;
 # enable CoreFilters
 pagespeed RewriteLevel CoreFilters;

The page itself seems to stack up;

This document was successfully checked as HTML5!
Result: Passed
Address:    
Encoding: utf-8 
Doctype:    HTML5   
Root Element:   html

Is there any way to log what's going on or any tools available to debug?

I've read this

Try appending ?ModPagespeed=off to the URL. This de-activates PageSpeed. If the site is still broken, it is not a rewrite or HTML parsing problem.

^ it works okay

If that fixed the site, try appending ?ModPagespeed=on&ModPagespeedFilters= to the URL. This turns on PageSpeed, but no filters. If the site is broken now, it is an HTML parsing problem. Please let us know.

^ nope, broken still

Is this 'HTML parsing problem' the issue I can't understand to solve?

Thanks for your time.

oschaaf commented 9 years ago

@DamienR What does error.log look like when this happens? Also, could you post (or PM) the original html source and response headers?

goregrish commented 9 years ago

Hi Oschaaf,

It's an adult video website so posting the link won't be possible here. The following data is with pagespeed off. I don't have anything recorded in site or nginx error logs. Just some old depreciated mysql errors.

GET / HTTP/1.1
Host: -snip-.com
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8,fr;q=0.6,ja;q=0.4,en-GB;q=0.2
Cookie: OGPC=270001-2:; SID=DQAAAAoBAABEvgh9cN76YAmAaY8l-JCul2QH-    7fBbMF60hH1Wd7L1rhSGzlZR1FfgxmxqcOiX_ooDUvIuAP1FstlrtOy4gPsJjHRml2H_pURJ79DeWtpRbnsjsX3foPMXfzh0BdSJp6csplvuHmLbvYycGI2e4QENGRlLP4qkEPgrQCEAWmWa539tsNcmFqynBxpqkulEBTtEFgtqfiCpUGtlglzGUYGyvJJnZUP5uDXObC_QId7BMMpNLuGVlnKP6H5wgOGkS2tBqUWe3htF98TpYG4iDAKT1hCHF1fQ-WRkDYLbakmWz0zXOOqnXJ4AxwQvhIyz0GcEk1DpNUt3LdjEZbJs-3LUM_R0EwEJgmUa0pS2wicTw; HSID=AHoujeH7fTsWTqZlQ; SSID=ACV-o95_iSjl7rOLP; APISID=A_rrGFdnQ6ktcjO0/Aju1Vgqt2xTa33-Ot; SAPISID=v4VYsY9Rj9oMnsOe/A-TwjRtM72rGepiVH; NID=67=L8apiWMHhbDvfpOb4wnLqtwtJXN-lXPnuRNl2oCELL8X2EnDgsy4p21V1HCbTHk346FT1qACMgLtEMw-8KfuEyHKU5CPjID1gCluZe279MJnm5_fviS7sqYxYp_xhuO7nTMh-0xjRfUg8llnKX5oUUsiUi7s0OZAjFp5krCiBj-Qdky14jm5ha7P8tt-jSK8tA; PREF=ID=2f892d4be9d28ff7:U=f4fc06ddffbae780:FF=0:LD=en:NR=10:TM=1423212399:LM=1425807543:SG=2:S=YbPqjfgxeZ747s3O
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)     Chrome/40.0.2214.115 Safari/537.36
X-Client-Data: CJS2yQEIpLbJAQiptskBCMG2yQEI64jKARiricoB

HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Sun, 08 Mar 2015 09:42:10 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive: timeout=2
Last-Modified: Sun, 08 Mar 2015 09:42:10 GMT
Pragma: no-cache
Server: nginx
Transfer-Encoding: chunked

Here's a link to full source code from the index (caution: contains nsfw text) http://pastebin.com/ruYrxygj

goregrish commented 9 years ago

wait what.

Expires: Thu, 19 Nov 1981 08:52:00 GMT

That can't be good, I was only a child when this expires.

oschaaf commented 9 years ago

@DamienR I don't see anything in the html source that strikes me as odd. I'll try to reproduce this with a proxy setup, and let you know how that goes.

goregrish commented 9 years ago

Thanks again,

I've tried using RewriteLevel OptimizeForBandwidth but had little luck there, same results. I have great success using this on wordpress installs with corefilters + some extra on the same server so it's a little puzzling what's different/holding it up just for this .php script in particular.

oschaaf commented 9 years ago

@DamienR I was able to reproduce this by reverse proxying the site via nginx + ngx_pagespeed . Looking at error.log, I noticed that there's a warning about corrupted inflation, followed by some messages from the html parser.

2015/03/08 23:35:05 [debug] 10752#0: [ngx_pagespeed 1.9.32.3-4448] [0308/233505:VERBOSE1:proxy_fetch.cc(550)] Attaching RewriteDriver 0x1e51110 to HtmlRewriter 0x1e59a70
2015/03/08 23:35:05 [debug] 10752#0: [ngx_pagespeed 1.9.32.3-4448] [0308/233505:VERBOSE1:proxy_fetch.cc(595)] Parse successfully started.
2015/03/08 23:35:05 [warn] 10752#0: [ngx_pagespeed 1.9.32.3-4448] [0308/233505:WARNING:google_message_handler.cc(38)] Corrupted inflation
2015/03/08 23:35:05 [debug] 10752#0: [ngx_pagespeed 1.9.32.3-4448] [0308/233505:VERBOSE1:proxy_fetch.cc(990)] Fetch result:1 http://foo.com:8053/ : 200
2015/03/08 23:35:05 [info] 10752#0: [ngx_pagespeed 1.9.32.3-4448] http://foo.com:8053/:172:End-of-file in mid-attribute-name: title
2015/03/08 23:35:05 [info] 10752#0: [ngx_pagespeed 1.9.32.3-4448] http://foo.com:8053/:172:End-of-file in mid-attribute-value: Little blonde has her as
2015/03/08 23:35:05 [info] 10752#0: [ngx_pagespeed 1.9.32.3-4448] http://foo.com:8053/:171:End-of-file with open tag: a
2015/03/08 23:35:05 [info] 10752#0: [ngx_pagespeed 1.9.32.3-4448] http://foo.com:8053/:170:End-of-file with open tag: div
2015/03/08 23:35:05 [info] 10752#0: [ngx_pagespeed 1.9.32.3-4448] http://foo.com:8053/:72:End-of-file with open tag: div
2015/03/08 23:35:05 [info] 10752#0: [ngx_pagespeed 1.9.32.3-4448] http://foo.com:8053/:41:End-of-file with open tag: div
2015/03/08 23:35:05 [info] 10752#0: [ngx_pagespeed 1.9.32.3-4448] http://foo.com:8053/:35:End-of-file with open tag: div

With curl I could also reproduce something similar, without ngx_pagespeed:

$ curl --compressed -H "Accept-Encoding: gzip" http://foo.com/ 
.... valid html...
        <img class="lazy img-responsive desktop-only" scurl: (23) Error while processing content unencoding: incorrect data check

So there's something going on with compression on you server that seems wrong. We might be able to improve the way we handle this situation in ngx_pagespeed, as Chrome seems to be able to recover better from this then we do.

goregrish commented 9 years ago

@oschaaf thanks so much for pointing me in the right direction, I appreciate you taking the time to proxy this. I've found the cause - and it's running fantastic now with a multitude of filters enabled.

_The PHP script calls the function | ob_start("ob_gzhandler"); to enable gzip'ed output and when the output is finished the function ||while (@ob_end_flush()); is called. These 2 instructions cause PHP to produce invalid gzip'ed data. If the ob_endflush() function is left out the output of the webserver is correct gzip'ed data.

Simply disabling gzip 'helper' in PHP and only letting the server deal with it cleared up all the issues.

oschaaf commented 9 years ago

@DamienR thanks, great to hear it is working!