putyourlightson / craft-blitz

Intelligent static page caching for creating lightning-fast sites with Craft CMS.
https://putyourlightson.com/plugins/blitz
Other
149 stars 36 forks source link

Caching works only for the primary site on a multisite setup #166

Closed luke-nehemedia closed 4 years ago

luke-nehemedia commented 4 years ago

I am testing blitz right now for a new client and have used it on two other sites for quite a while. Until now without major problems.

This time, however, the site has multiple languages with multiple domains. I have et it up to include all urls of the 3 main languages (by choosing the site and entering .*. I have excluded some sites that include forms. I also added the Rewrite rules to the .htaccess file.

screen1

I visited the site on multiple devices and clicked on "warm cache." As a result, it cached the first language, but left the other sites untouched.

screen2

I tried a couple of things:

However, I could not get the plugin to cache the other language versions.

Any idea how to solve this?

Versions

bencroker commented 4 years ago

First check the common issues and if you don't find a solution there then enabling the debug config setting should help you figure out why pages are not being cached.

luke-nehemedia commented 4 years ago

Thanks for the answer. I already went through the common issues, but nothing helped.

Enabling the debug setting results in messages stating, that... Page not cached because it does not match an included URI pattern.

However, as stated above, everything is included in the URI pattern. I also removed the exceptions temporarily, which did not resolve the problem.

I have tried out a couple of other things:

bencroker commented 4 years ago

What is the base URL set to in the site settings for the secondary site? Is it an absolute URL? Can you compare it to the exact URL in the log file message?

luke-nehemedia commented 4 years ago

The base URLs of the secondary sites are all absolute URLs set via the CP, not via environmental variables etc.

They do match exactly the URLs given in the Log-file.

bencroker commented 4 years ago

Ok, can you send the log file to info@putyourlightson.net and we'll take a closer look?

luke-nehemedia commented 4 years ago

I just mailed the log-files and screenshots (without blacked-out parts) of the Blitz-Settings and Site-Settings.

sarahschuetz commented 4 years ago

I have the same/similar Problem. Only the primary site gets cached when prewarming. However, single pages of all sites are cached when visited.

Plugin version: 3.1.0 Craft version: 3.3.18.2

bencroker commented 4 years ago

@sarahschuetz Have you tried enabling the debug config setting and what is the result of the log?

bencroker commented 4 years ago

Also, is the base URL in the site settings for the secondary site an absolute URL? Please ensure that you are not using @web (without defining it explicitly).

bendesilva commented 4 years ago

I was also similar experiencing issues with Blitz on a multi-site website yesterday, but instead it was returning stale cached versions for pages, and whatever I did I wasn't able to clear the cache for the localised site.

I realised the issue was with my config settings as I was using a relative path ('folderPath' => 'cache/blitz') as per the v2 config file. There seemed to be a discrepancy between the files being stored in the web root for the primary site (/web/cache/blitz/example.com) and the web root for the localised site (/web/zh-hans/cache/blitz/example.com/zh-hans). After changing this to an absolute folder path rather than relative in the config via an ENV variable (e.g. /home/user/example.com/web/cache/blitz) it appeared to work as expected and all cached files were being stored in the primary web root rather than in any additional sites' web root. It seems the v3 config now uses ['folderPath' => '@webroot/cache/blitz'].

It could be because I'm using a nested web root for the localised site that this occurred in the first place, it may not be the case for separate web roots, or multi site where there's a single web root.

Not sure if that's applicable for any other cases here, but that certainly helped my issue. FYI the above config was seemingly working fine for a while until I recently updated Blitz.

bencroker commented 4 years ago

@bendesilva Thank you for your input. You're right that the folder path was changed from a relative path to an absolute path , so in version 3 it should be @webroot/cache/blitz or similar.

The update migration from v2 to v3 automatically added the @webroot prefix to the folder path, but the setting probably got overwritten when you performed a more recent update to Blitz and saved the settings with the old folder path value set in your config file.

I'm not sure if this is the same issue that @luke-nehemedia and @sarahschuetz are facing, but it would be worthwhile double checking.

sarahschuetz commented 4 years ago

@bencroker sorry, for my late response and thank you for your effort. I just had time to review the issue again and came up with the following results:

sarahschuetz commented 4 years ago

Here is an excerpt of the logs:

2020-02-11 11:15:48 [][][debug] Template not found: c/datenschutzbestimmungen
2020-02-11 11:15:48 [][][debug] Template not found: c/termine-und-preise-1
2020-02-11 11:15:48 [][][debug] Template not found: c/anmeldebestaetigung-ausbildungsplatz
2020-02-11 11:17:16 [][][debug] Page not cached because it matches an excluded URI pattern. [http://xxx.test/csrf/]
2020-02-11 11:20:50 [][][debug] Page not cached because it matches an excluded URI pattern. [http://xxx.test/csrf/]
bencroker commented 4 years ago

@sarahschuetz where exactly are you defining @baseUrl for the various sites? Can you show the specific code sample?

sarahschuetz commented 4 years ago

@bencroker the aliases are defined in config/general.php:

'aliases' => [
            '@baseUrl' => getenv('SITE_URL'),
            '@baseUrlEn' => getenv('SITE_URL') . 'en/',
            '@baseUrlB2b' => getenv('SITE_URL') . 'r/',
            '@baseUrlB2bEn' => getenv('SITE_URL') . 'en/r/',
            '@baseUrlxxxDe' => getenv('SITE_URL') . 'c/',
            '@baseUrlxxxEn' => getenv('SITE_URL') . 'en/c/',
        ],

... and SITE_URL in my .env file is:

SITE_URL="http://xxx.test/"
bencroker commented 4 years ago

That looks good @sarahschuetz. Can you send the log file (be sure to enable the debug config setting first), detailing what URL specifically is not being warmed, to info@putyourlightson.net and I'll take a closer look? If you are able to send login credentials then that would be helpful too.

bencroker commented 4 years ago

Please test using the Guzzle warmer, which is the recommended warmer. The Local warmer is not as stable for multi-site setups.

sarahschuetz commented 4 years ago

@bencroker Thanks for all your help. Using Guzzle Warmer all our multi-sites are cached now 🎉

bencroker commented 4 years ago

Great, glad to hear it!

luke-nehemedia commented 4 years ago

Hello again

I am very sorry to answer that late, but due to personal circumstances I wasn't able to work on this project in the meantime.

Sadly enough, the problem is still there.

Some stuff I have tried with regard to the conversation:

I have really no idea why it behaves so strange. On all other sites it works just fine. However, none of the other ones is a multisite.

bencroker commented 4 years ago

@luke-nehemedia Please email credentials to the site to info@putyourlightson.net and we'll take a closer look.

luke-nehemedia commented 4 years ago

You should have received the credentials now.

luke-nehemedia commented 4 years ago

Latest update solved the issue! Thank you!

belkin commented 3 years ago

@bencroker I have the same problem on multisite setup. Blitz caching is enabled and 'Included URI Patterns' left empty only to cache the homepage. It caches only the primary website but not the other websites. I've tried with .* but no difference there.

Craft version: 3.4.27 Blitz version: 3.8

Urls are generated via .env file and general.php. ENV: BASE_URL="https://local.page.com/" general.php: 'aliases' => [ 'baseUrl' => trim(getenv('BASE_URL'), '/'), ],

image

When I enable the debug mode then I'm just getting: 2021-04-22 08:41:43 [][6][debug] Page not cached because it does not match an included URI pattern. [https://local.page.com/nl]

bencroker commented 3 years ago

@belkin this issue is closed and over a year old. Please create a new issue with some more details/screenshots of your settings and we'll take a look.