Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache recreated on each page load #2156

Open
piotrbak opened this issue Dec 5, 2019 · 17 comments
Open

Cache recreated on each page load #2156

piotrbak opened this issue Dec 5, 2019 · 17 comments
Labels
module: cache module: cloudflare needs: grooming priority: high Issues which should be resolved as quickly as possible

Comments

@piotrbak
Copy link
Contributor

piotrbak commented Dec 5, 2019

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:

$cache_filepath = $this->get_cache_path();

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

@webtrainingwheels
Copy link

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

@GeekPress
Copy link
Contributor

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

@piotrbak
Copy link
Contributor Author

@GeekPress For Cloudflare it was resolved in our add on, I believe:

if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] ) {

@GeekPress
Copy link
Contributor

@GeekPress
Copy link
Contributor

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

@piotrbak
Copy link
Contributor Author

@GeekPress Done

@GeekPress
Copy link
Contributor

@piotrbak Awesome, thanks 🤚

@Tabrisrp
Copy link
Contributor

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.

@girlie
Copy link
Contributor

girlie commented Jul 15, 2020

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

@vmanthos
Copy link
Contributor

@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.

@Tabrisrp
Copy link
Contributor

@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.

@arunbasillal
Copy link
Contributor

@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.

@NataliaDrause
Copy link
Contributor

@NataliaDrause
Copy link
Contributor

@viobru
Copy link
Contributor

viobru commented Dec 14, 2021

@camilamadronero-zz
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: cache module: cloudflare needs: grooming priority: high Issues which should be resolved as quickly as possible
Projects
None yet
Development

No branches or pull requests

10 participants