Suspected cache problems (detailed)
-
Hello,
Just experienced some weird cache problems. Related to WP Super Cache, but not necessarily a bug. Just want to confirm the actual cause, so it does not happen again.
SummarySite is proxied through CloudFlare. PHP 7.4.33. Apache virtual host, Ubuntu Server 22.04.
Compress pages so they’re served more quickly to visitors. (Recommended): Enabled
When navigating to pages on my domain, it triggered a .gz download in Firefox. Probably would have in Chrome too – but use Chrome daily, so browser cache probably masked the problem.
Rollback to default theme did not solve the problem, nor disabling Autoptimize (which should not serve gzip anyways). Clearing WP Super Cache did solve the problem, for now.
Detailed
Allright, as stated in the summary. Suddenly one of our sites started serving .gz files instead of the actual webpage. Analyzed file online (not locally in case of injected files). Contents (one file) inside .gz, with no file extension, does indeed contain the cached page.
As per documentation:
- Cache files: Both wp-cache-config.php and advanced-cache.php are present in ../wp-content/
- wp-config.php: define( ‘WP_CACHE’, true ); present in wp-config.php, before require_once(ABSPATH.’wp-settings.php’);
- php.ini: zlib.output_compression = Off
- mod_mime, mod_headers and mod_expires: All enabled
Extra cache control, htaccess:
<FilesMatch "\.(js|css|jpg|gif|png|pdf|swf|svg|svgz|ico|ttf|ttc|otf|eot|woff|woff2|webp)$">
<IfModule mod_headers.c>
ExpiresActive On
ExpiresDefault "access plus 6 month"
Header set Cache-Control "public, immutable, max-age=15780000, s-maxage=15780000"
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>Figured it was a cache problem, obviously. Inspected response headers. Browser does as instructed by content-type when error occurred (download gzip), but obviously not wanted. Relevant:
- Content-type when error occurred: application/x-gzip
- Content-type after clearing cache, back to normal: text/html; charset=UTF-8
Suspected problem
- Content-encoding: zstd – must be CloudFlare.
- Have other websites running WP Super Cache (same server and setup), where encoding is gzip as expected. Those are not proxied through CloudFlare.
- mod_deflate: Enabled – but zlib compression disabled. Either way, never had a problem with that for 5 years.
So… Any ideas? I suspect conflicting caching between WP Super Cache / CloudFlare, or conflict with mod_deflate.
Solution may be as simple as disabling “Compress pages so they’re served more quickly to visitors“?
Regardless of solution, also want input on why content-type was served as application/x-gzip. Can’t see how CloudFlare would affect exactly that.
Would very much like to get to the bottom of this, so it does not happen again. With local browser caching, it’s hard to know when these kind of errors occur.
- You must be logged in to reply to this topic.