Search code examples
wordpressnginxplesk

Exclude folders from caching


In Plesk under Additional nginx directives I've added the following cache settings.

location ~* .(jpg|js|css)$ { #shortened
    etag on;
    if_modified_since exact;
    add_header Pragma "public";
    add_header Cache-Control "max-age=31536000, public";
}

But in the wp-admin I have rewrites on the url's of these type of files.
How Do I exclude wp-admin/* and wp-includes/* from the block above?

Bit of background, I run a WordPress multisite in a subfolder. so
maildomain.com/wp-admin/stylesheet.css is actually located in
maildomain.com/wp/wp-admin/stylesheet.css


Solution

  • You can try to experiment with location parameter before caching directives, e.g.:

    location ^~ /wp-admin/ {
    }
    
    location ~* .(jpg|js|css)$ { #shortened
    etag on;
    if_modified_since exact;
    add_header Pragma "public";
    add_header Cache-Control "max-age=31536000, public";
    }
    

    UPD. Yes, checked it on my test lab and got the 403 error. I guess empty section is not enough and some directives should be added explicitly.

    Managed to add exclusion like the one below:

    location ~* "^/(?!wp-admin/|wp-includes/).*\.(jpg|js|css)$" { #shortened
    etag on;
    if_modified_since exact;
    add_header Pragma "public";
    add_header Cache-Control "max-age=31536000, public";
    }