wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

Cache recreated on each page load

Open piotrbak opened this issue 5 years ago • 20 comments

When the site is using HTTPS but $_SERVER array values are wrongly set to HTTP and port 80 (it can happen with Cloudflare flexible SSL for example), the cache is recreated on each page load.

It happens because $cache_filepath points to the index.html file instead of index-https.html: https://github.com/wp-media/wp-rocket/blob/281eb493f44e873a9685f379cec701e8ebcf3532/inc/classes/Buffer/class-cache.php#L93

When it's related to Cloudflare (haven't seen it happening on other proxies), setting values of the array in wp-config.php file resolves the problem: if ( isset( $_SERVER["HTTP_X_FORWARDED_PROTO"] ) && $_SERVER["HTTP_X_FORWARDED_PROTO"] == "https" ) { $_SERVER["HTTPS"] = "on"; }

Steps to reproduce:

  1. On shared hosting environment create a site which uses HTTP
  2. Make sure that HTTPS (private_html directory) version is symlinked to the public_html directory. Then the HTTPS version will be pointing to the HTTP one
  3. Visit the not secured version of the page. or
  4. Add a certificate that will secure the route from browser to proxy, but not from proxy to the server (just like Cloudflare Flexible SSL) and visit the page.
  5. The cache should be created, refresh the page and confirm that the file was recreated.

Related tickets: https://secure.helpscout.net/conversation/1005343810/131288/ https://secure.helpscout.net/conversation/1019496418/134235?folderId=1213662

piotrbak avatar Dec 05 '19 15:12 piotrbak

Another case, fixed with the wp-config modification above https://secure.helpscout.net/conversation/1046050894/139175?folderId=377611

webtrainingwheels avatar Jan 08 '20 22:01 webtrainingwheels

@piotrbak If you remember, could you please add the Steps to reproduce section?

GeekPress avatar Jun 10 '20 20:06 GeekPress

@GeekPress For Cloudflare it was resolved in our add on, I believe: https://github.com/wp-media/wp-rocket/blob/e40b824350a165cf52f2285a681d5b6796ed5555/inc/common/cloudflare-flexible-ssl.php#L107

piotrbak avatar Jun 10 '20 20:06 piotrbak

From the dev team, it still needs to be fixed: https://wp-media.slack.com/archives/GUT7FLHF1/p1591822316013300?thread_ts=1591821922.012200&cid=GUT7FLHF1

GeekPress avatar Jun 10 '20 20:06 GeekPress

@piotrbak Then, I re-ask the question about the Steps to reproduce 😇

GeekPress avatar Jun 10 '20 20:06 GeekPress

@GeekPress Done

piotrbak avatar Jun 12 '20 22:06 piotrbak

@piotrbak Awesome, thanks 🤚

GeekPress avatar Jun 15 '20 08:06 GeekPress

When the initial cache file is created, is it using the index.html name, or the index-https.html name?

I'm failing to see how it can happen, all the methods reading and writing use the same method get_cache_path() to get the full path to the cache file, so they should all use the same value.

remyperona avatar Jul 13 '20 20:07 remyperona

Another case (fixed per above): https://secure.helpscout.net/conversation/1221685493/179588/

girlie avatar Jul 15 '20 17:07 girlie

https://secure.helpscout.net/conversation/1310206323/202680?folderId=2135277#thread-3783962460

webtrainingwheels avatar Oct 22 '20 20:10 webtrainingwheels

@webtrainingwheels

Thank you for reporting this. 👆

In this case, HTTP_X_FORWARDED_PROTO was http despite them having https.

The issue was resolved by adding the following in the wp-config.php: $_SERVER['HTTPS'] = 'on';

@Tabrisrp

When the initial cache file is created, is it using the index.html name, or the index-https.html name?

The initial file is index-https.html, but we are looking for index.html.

vmanthos avatar Oct 23 '20 06:10 vmanthos

@arunbasillal This all seems to come from a misconfiguration on the server side, WP Rocket is behaving as expected based on the configuration provided.

I don't think we can do anything to fix this automatically, the issue is happening even before the plugin starts to do its work.

remyperona avatar Dec 17 '20 20:12 remyperona

@Tabrisrp Thanks for your feedback.

Thinking out loud. Why do we need to add -https to the filename? Wouldn't the HTTP and HTTPS versions be the same in most (or all) cases? I am thinking a rework here could be tricky and risky, but in turn would avoid this problem. Band-aid of course.

arunbasillal avatar Dec 21 '20 13:12 arunbasillal

Related: https://secure.helpscout.net/conversation/1428638992/240291/

NataliaDrause avatar Feb 24 '21 10:02 NataliaDrause

Related: https://secure.helpscout.net/conversation/1674678557/303724/

NataliaDrause avatar Oct 25 '21 19:10 NataliaDrause

Related: https://secure.helpscout.net/conversation/1725284929/314015

viobru avatar Dec 14 '21 11:12 viobru

new case https://secure.helpscout.net/conversation/1942637809/354472/

camilamadronero-zz avatar Jul 14 '22 20:07 camilamadronero-zz