从缓存中排除文件夹

Exclude folders from caching

Additional nginx directives 下的 Plesk 中,我添加了以下缓存设置。

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

但是在 wp-admin 中我重写了 url 这些类型的文件。
如何从上面的块中排除 wp-admin/*wp-includes/*

一些背景知识,我 运行 子文件夹中的 WordPress 多站点。所以
maildomain.com/wp-admin/stylesheet.css实际位于
maildomain.com/wp/wp-admin/stylesheet.css

您可以尝试在缓存指令之前使用 location 参数,例如:

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";
}

更新。是的,在我的测试实验室中进行了检查并得到了 403 错误。我想空白部分是不够的,应该明确添加一些指令。

设法添加如下排除项:

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";
}