cms icon indicating copy to clipboard operation
cms copied to clipboard

DEBUG: Static cache loaded: If you are seeing this, your server rewrite rules have not been set up correctly.

Open stuartcusackie opened this issue 8 months ago • 9 comments

Bug description

Hi,

It appears that this issue has not been solved. My logs are full of entries like these. I have opened an issue with Statamic Support but I thought I'd open it here too.

  • This problem occurs on every site where I have enabled full-measure Static caching. It does not occur on my sites that use half-measure.
  • It happens on both multi-sites and non-multi-sites
  • I am a Blade developer using the @nocache directive.
  • I am using the exact configuration provided by the docs.

Nginx.conf

Here is my nginx.conf for one of my multi-sites on Forge. Note that: ignore_query_strings = false on this particular site, but it happens on other sites where this value is true.

# Start Original Forge Location Block
# location / {
#     try_files $uri $uri/ /index.php?$query_string;
# }
# End Original Forge Location Block
    
set $try_location @static;
     
if ($request_method != GET) {
  set $try_location @not_static;
}
     
if ($args ~* "live-preview=(.*)") {
  set $try_location @not_static;
}
     
location / {
  try_files $uri $try_location;
}
     
location @static {
  try_files /static/${host}${uri}_$args.html $uri $uri/ /index.php?$args;
}
     
location @not_static {
  try_files $uri /index.php?$args;
}

How to reproduce

Logs

[2025-04-28 20:34:00] production.DEBUG: Static cache loaded [https://www.mysite.co.uk/] If you are seeing this, your server rewrite rules have not been set up correctly.  

Environment

# This is happening on 5 different Statamic sites, both multisite and non-multisite. Different versions.
# The main thing they all have in common is that they use full-measure static caching and the blade @nocache directive.
# Here is the environment for one of the multisites:

Environment
Laravel Version: 11.37.0
PHP Version: 8.2.18
Composer Version: 2.8.8
Environment: production
Debug Mode: ENABLED
URL: www.mysite.ie
Maintenance Mode: OFF
Timezone: Europe/Dublin
Locale: en

Cache
Config: CACHED
Events: CACHED
Routes: CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single, slack
Mail: smtp
Queue: redis
Session: file

Livewire
Livewire: v3.5.18

Statamic
Addons: 6
Sites: 3 (mysite.ie, mysite.co.uk, mysite.com)
Stache Watcher: Disabled (auto)
Static Caching: full
Version: 5.45.0 PRO

Statamic Addons
aerni/livewire-forms: 9.4.1
jonassiewertsen/statamic-livewire: 3.8.1
pecotamic/sitemap: 1.4.7
spatie/statamic-responsive-images: 5.2.1
stuartcusackie/statamic-cache-requester: 1.2.7
stuartcusackie/statamic-seo: 0.9.2



Installation

Fresh statamic/statamic site via CLI

Additional details

No response

stuartcusackie avatar Apr 29 '25 09:04 stuartcusackie

Are you able to provide the full contents of config/statamic/static_caching.php?

Also, can you try using a simplified version of the Nginx config to see if that helps at all?

location / {
  try_files /static/${host}${uri}_${args}.html $uri /index.php?$args;
}

duncanmcclean avatar Apr 29 '25 09:04 duncanmcclean

Thanks for the suggestion. I will try that out on my multisite asap. I'm just waiting for test results on another experiment. Do you know if I need to edit the nginx.conf for every domain for a multisite on Forge, or would it just be for the domain where Statamic is installed? Previously I only updated the nginx.conf for the Statamic install site (primary site).

I can try this new location block on a non-multisite site now. Changing from:

try_files /static${uri}_$args.html $uri $uri/ /index.php?$args;

To this:

try_files /static${uri}_${args}.html $uri /index.php?$args;

UPDATE: I can still see some of these error log warnings occuring.

PS. I can share config/static_caching.php but as mentioned, this is occurring on 4 or 5 sites, each of them has a different config. The only settings that I usually edit are the invalidation rules.

stuartcusackie avatar Apr 29 '25 10:04 stuartcusackie

Do you know if I need to edit the nginx.conf for every domain for a multisite on Forge, or would it just be for the domain where Statamic is installed? Previously I only updated the nginx.conf for the Statamic install site (primary site).

How are you handling the multiple domains in Laravel Forge?

Do you have one site with multiple domains configured, or do you have a site for each domain, with the public path pointing to the site with Statamic installed?

PS. I can share config/static_caching.php but as mentioned, this is occurring on 4 or 5 sites, each of them has a different config. The only settings that I usually edit are the invalidation rules.

Yes please. It'll help us ensure we're replicating with the same setup.

duncanmcclean avatar Apr 29 '25 13:04 duncanmcclean

I'm afraid the simpler version of the nginx.conf location block doesn't fix it.

On Laravel Forge, I have the main site installed as usual, then I have one site for every additional domain. I simply update the root path in nginx.conf on the secondary sites like so:

root /home/forge/www.primarysite.ie/public;

But as mentioned, I don't think this is the issue because I see these debug messages on non multi-sites too.

Here is the config/statamic/static_caching.php for one of my sites (non-multisite - full measure):

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Active Static Caching Strategy
    |--------------------------------------------------------------------------
    |
    | To enable Static Caching, you should choose a strategy from the ones
    | you have defined below. Leave this null to disable static caching.
    |
    */

    'strategy' => env('STATAMIC_STATIC_CACHING_STRATEGY', null),

    /*
    |--------------------------------------------------------------------------
    | Caching Strategies
    |--------------------------------------------------------------------------
    |
    | Here you may define all of the static caching strategies for your
    | application as well as their drivers.
    |
    | Supported drivers: "application", "file"
    |
    */

    'strategies' => [

        'half' => [
            'driver' => 'application',
            'expiry' => null,
        ],

        'full' => [
            'driver' => 'file',
            'path' => public_path('static'),
            'lock_hold_length' => 0,
            'permissions' => [
                'directory' => 0755,
                'file' => 0644,
            ],
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Exclusions
    |--------------------------------------------------------------------------
    |
    | Here you may define a list of URLs to be excluded from static
    | caching. You may want to exclude URLs containing dynamic
    | elements like contact forms, or shopping carts.
    |
    */

    'exclude' => [
        '/!/static-vars/*',
        '/lightbox-image-asset'
    ],

    /*
    |--------------------------------------------------------------------------
    | Invalidation Rules
    |--------------------------------------------------------------------------
    |
    | Here you may define the rules that trigger when and how content would be
    | flushed from the static cache. See the documentation for more details.
    | If a custom class is not defined, the default invalidator is used.
    |
    | https://statamic.dev/static-caching
    |
    */

    'invalidation' => [

        'class' => null,

        'rules' => [
            'collections' => [
                'events' => [
                    'urls' => [
                        '/events'
                    ]
                ],
                'exhibitions' => [
                    'urls' => [
                        '/'
                    ]
                ]
            ],
            'globals' => [
                'global_configuration' => [
                    'urls' => [
                        '/*'
                    ]
                ],
                'global_images' => [
                    'urls' => [
                        '/*'
                    ]
                ],
                'global_seo' => [
                    'urls' => [
                        '/*'
                    ]
                ],
                'global_social' => [
                    'urls' => [
                        '/*'
                    ]
                ]
            ],
            'navigation' => [
                'main' => [
                    'urls' => [
                        '/*'
                    ]
                ],
                'cta' => [
                    'urls' => [
                        '/*'
                    ]
                ],
                'footer' => [
                    'urls' => [
                        '/*'
                    ]
                ],
            ],
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Ignoring Query Strings
    |--------------------------------------------------------------------------
    |
    | Statamic will cache pages of the same URL but with different query
    | parameters separately. This is useful for pages with pagination.
    | If you'd like to ignore the query strings, you may do so.
    |
    */

    'ignore_query_strings' => false,

     /*
    |--------------------------------------------------------------------------
    | Replacers
    |--------------------------------------------------------------------------
    |
    | Here you may define replacers that dynamically replace content within
    | the response. Each replacer must implement the Replacer interface.
    |
    */

    'replacers' => [
        \Statamic\StaticCaching\Replacers\CsrfTokenReplacer::class,
        \Statamic\StaticCaching\Replacers\NoCacheReplacer::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Warm Queue
    |--------------------------------------------------------------------------
    |
    | Here you may define the queue name and connection
    | that will be used when warming the static cache.
    |
    */

    'warm_queue' => env('STATAMIC_STATIC_WARM_QUEUE'),

    'warm_queue_connection' => env('STATAMIC_STATIC_WARM_QUEUE_CONNECTION'),


    /*
    |--------------------------------------------------------------------------
    | Shared Error Pages
    |--------------------------------------------------------------------------
    |
    | You may choose to share the same statically generated error page across
    | all errors. For example, the first time a 404 is encountered it will
    | be generated and cached, and then served for all subsequent 404s.
    |
    | This is only supported for half measure.
    |
    */

    'share_errors' => false,

];

stuartcusackie avatar Apr 29 '25 17:04 stuartcusackie

On Laravel Forge, I have the main site installed as usual, then I have one site for every additional domain. I simply update the root path in nginx.conf on the secondary sites like so:

Just to confirm, do you have the Nginx rules configured on the secondary sites too?

duncanmcclean avatar Apr 30 '25 08:04 duncanmcclean

Just to confirm, do you have the Nginx rules configured on the secondary sites too?

I tried this yesterday and added the rules to all secondary sites. It didn't solve the problem.

stuartcusackie avatar Apr 30 '25 08:04 stuartcusackie

We're having the same problem for one specific site. I also tried the alternative nginx rule but it actually made things worse for some reason.

espenlg avatar May 14 '25 22:05 espenlg

We're having the same issue with full static caching + default .htaccess config from the documentation, on our multi-site Statamic 5 site (same codebase, just multiple domains setup):

# Statamic Static Caching

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !live-preview
RewriteRule ^ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} live-preview
RewriteRule ^ index.php [L]

RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}_%{QUERY_STRING}\.html -s
RewriteCond %{REQUEST_METHOD} GET
RewriteRule .* static/%{REQUEST_URI}_%{QUERY_STRING}\.html [L,T=text/html]

jonathan-bird avatar Nov 28 '25 03:11 jonathan-bird

Just had this issue on one of my sites, again with nginx configuration as documented. There's a side effect that some requests that follow this pattern of behaviour don't return any response - they just hang. It also appears intermittent.

The only resolution for me is to disable caching.

HighLifeHighland avatar Dec 03 '25 09:12 HighLifeHighland