-
-
Notifications
You must be signed in to change notification settings - Fork 569
[5.x] Fix static cache file paths for multisite setups #11724
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
base: 5.x
Are you sure you want to change the base?
[5.x] Fix static cache file paths for multisite setups #11724
Conversation
a03bd54
to
c047ede
Compare
Thank you but when you use separate domains or subdomains, you should be configuring the paths. See from https://statamic.dev/static-caching#paths on. 'strategies' => [
'full' => [
'driver' => 'file',
'path' => [
'english' => public_path('static') . '/domain.com/',
'french' => public_path('static') . '/domain.fr/',
'german' => public_path('static') . '/domain.de/',
],
],
], |
Hey, that's exactly what I am doing. But the site falls back to the config locale, which in my case is not being used, we have subdomains like b2b.customer.com, company.customer.com etc. as our sites. So when it goes to the non-default site it will just fallback to config('locale'), which will lead to no cached entry. The related piece of code is below, $site is null when no explicitly passed, which is why my PR would make sure that it is always passed. Related code below for reference. Let me know if you need a repo to reproduce this 🙂
|
Yeah a repo would be helpful, thanks. |
Here you go: https://github.com/ChristianPraiss/multisite-caching-demo Steps to reproduce:
![]() |
I see, in that case I guess the naming confused me a bit, because I wouldn't expect something named paths to contain a hostname. Will try it in our project once I get back to work tomorrow and close this issue if that fixes it! Thx so far! |
The keys of the Your default:
name: ...
url: 'http://domainone.com/'
locale: ...
web2:
name: ...
url: 'http://domaintwo.com/'
locale: ... Your 'paths' => [
'default' => public_path('static').'/domainone.com/',
'web2' => public_path('static').'/domaintwo.com/',
] When Statamic needs to write a file for a specific site, it will plop it into a path containing the host. That's why the array needs to be keyed by site handles. It's also why you're seeing When Nginx tries to serve a page, it doesn't have knowledge of your Statamic site configuration. It only knows the host, so it tries to serve a file from a directory containing the host name. That's why the directories need to have host names. |
Yeah I understood that part, I was expecting putting the domains in the paths to fail. So my actual config I am encountering this issue with is this (exactly like your example above, only with different domains of course). When applying my patch it works perfectly, placing everything in it's domain-named folders in the public/static directory. Without it it only writes to the public/static/knbr.dev/ folder and the other domain folders are never created.
|
The |
Yeah we even have the setup through env variables that way, but the problem remains the same. I guess we can go with a vendor patch for our specific project, but I still feel like this should work out of the box according to what's in the docs 😄 |
@jasonvarga Asking the other way around: Is there any reason my change would not work? Or a specific reason why the site parameter would not be passed in some cases? I've just deployed our patched setup yesterday and it works properly, creating all cache folders named according to their sites domain and also reading back from them. |
Everything appears to work on my end because we merge the locale of the "current" site into the static cache config here.
But, if for some reason Making Are you able to find out what Route::get('/test', function () {
dump(\Statamic\Facades\Site::current(), request()->getUri());
}); Then you can visit |
This PR fixes an issue with static caching in multisite setups. It was forgotten to add the site parameter in all places where the cache path is calculated, leading to all sites overriding the default site's content in setups that use separate subdomains for the sites.