Files
LEMPer/etc/nginx/includes/rules_fastcgi_cache.conf
2019-09-27 21:38:16 +07:00

93 lines
2.5 KiB
Plaintext

## FastCGI Cache Rules.
# Designed to be included in any server {} block.
# Set caching conditions.
#set $skip_cache 0;
# WP Supercache related stuff.
#set $cache_uri $request_uri;
# POST requests and urls with a query string should always go to PHP.
#if ($request_method = POST) {
# set $skip_cache 1;
# set $cache_uri "null cache";
#}
# Skip caching if query string not empty.
if ($query_string != "") {
set $skip_cache 1;
set $cache_uri "null cache";
}
# Skip caching for custom header request.
if ($http_x_custom_header) {
set $skip_cache 1;
set $cache_uri "null cache";
}
# Skip caching for Search Engine Bot crawler.
if ($http_user_agent ~* "baiduspider|(ahref|alexa|bing|google|msn|yandex)bot|yahoo") {
set $skip_cache 1;
set $cache_uri "null cache";
}
# Skip caching for uris containing the following segments.
if ($request_uri ~* "apc.php|(mem|op)cache.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml") {
set $skip_cache 1;
set $cache_uri "null cache";
}
# Skip caching on admin pages.
if ($request_uri ~* "^(/account/*|/admin/*|/backend/*|/dashboard/*)") {
set $skip_cache 1;
set $cache_uri "null cache";
}
## WordPress-related Cache Rules ##
## Skip caching for uris containing the following segments.
if ($request_uri ~* "index.php|upgrade.php|update-core.php|/wp-admin|/wp-json|/xmlrpc.php|wp-*.php|/feed/|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml") {
set $skip_cache 1;
set $cache_uri "null cache";
}
# Skip caching on WooCommerce pages.
if ($request_uri ~* "^(/addons.*|/basket.*|/cart.*|/checkout.*|/my-account.*|/shop.*)") {
set $skip_cache 1;
set $cache_uri "null cache";
}
# Skip caching for logged in users or recent commenters.
if ($http_cookie ~* "(comment_author|wp-postpass|wordpress_no_cache|wordpress_logged_in|users_login_cookie|wordpress_[a-f0-9]+)") {
set $skip_cache 1;
set $cache_uri "null cache";
}
# Skip caching for WooCommerce query string.
if ($arg_add-to-cart ~ "[0-9]+") {
set $skip_cache 1;
set $cache_uri "null cache";
}
# Skip caching when WooCommerce cart is not empty (cookie set to 1).
if ($cookie_woocommerce_items_in_cart = "1" ) {
set $skip_cache 1;
set $cache_uri "null cache";
}
## Purging FastCGI cache ##
# Purge uri.
location ~ /purge(/.*) {
allow 127.0.0.1;
deny all;
access_log off;
log_not_found off;
fastcgi_cache_purge FASTCGICACHE "$scheme$request_method$host$1";
#return 301 $scheme://$host$uri;
}
## You may add your own FastCGI cache rules here...