这是我通常用来专门为Wordpress/Woocommerce网站禁用快速CGI缓存的块,它可能有帮助:
#disabler
set $no_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $no_cache 1;
}
if ($request_method = PATCH) {
set $no_cache 1;
}
if ($query_string != "") {
set $no_cache 1;
}
# Don't cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/wp-login/|/xmlrpc.php|index.php|phpmyadmin|sitemap(_index)?.xml|sitemap$") {
set $no_cache 1;
}
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $no_cache 1;
}
if ($request_uri ~* "(/wp-admin/|/cart/|/checkout/|/account/|/mon-compte/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $no_cache 1;
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|postpass|wordpress_n$") {
set $no_cache 1;
}
# Woocommerce
if ($request_uri ~* "/store.*|/cart.*|/my-account.*|/checkout.*|/addons.*|/panier.*|/paiement.*|/mon-compte.*") {
set $no_cache 1;
}
if ( $arg_add-to-cart != "" ) {
set $no_cache 1;
}
# need more tests
#if ( $cookie_woocommerce_items_in_cart != "0" ) {
# set $no_cache 1;
#}
if ( $cookie_woocommerce_items_in_cart ) {
set $no_cache 1;
}
这是我找到的多篇文章和要点的集合。请注意,我通常在每个块中添加头以查看在测试期间禁用缓存的是什么。有些规则可能重复。
当然,实现全部或部分这一点需要测试。
Wordpress Nginx Helper
插件,这对于全局和条件清除非常有用。