Add skip reason headers and woocommerce rules for fastcgi-cache

This commit is contained in:
Leo Semenenko 2019-11-13 03:20:04 -06:00
parent 5c526e7074
commit ce1dff7329
4 changed files with 30 additions and 4 deletions

5
conf.d/.gitignore vendored
View File

@ -1,2 +1,3 @@
# Ignore custom module config # Ignore custom module config
/* /*
!.gitignore

View File

@ -10,9 +10,12 @@ fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
# Show the cache status in server responses. # Show the cache status in server responses.
add_header Fastcgi-Cache $upstream_cache_status; add_header Fastcgi-Cache $upstream_cache_status;
add_header Fastcgi-Cache-Skip $skip_reason;
add_header REQUEST_URI $request_uri;
# Don't skip by default # Don't skip by default
set $skip_cache 0; set $skip_cache 0;
set $skip_reason "";
# POST requests and urls with a query string should always go to PHP # POST requests and urls with a query string should always go to PHP
if ($request_method = POST) { if ($request_method = POST) {
@ -21,14 +24,32 @@ if ($request_method = POST) {
if ($query_string != "") { if ($query_string != "") {
set $skip_cache 1; set $skip_cache 1;
set $skip_reason "QueryString${skip_reason}";
} }
# Don't cache uris containing the following segments # Don't cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/wp-json/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") { if ($request_uri ~* "/wp-admin/|/wp-json/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $skip_cache 1; set $skip_cache 1;
set $skip_reason "URI${skip_reason}";
} }
# Don't use the cache for logged in users or recent commenters # 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") { if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1; set $skip_cache 1;
set $skip_reason "LoggedIn${skip_reason}";
}
if ($request_uri ~* "/store.*|/cart.*|/my-account.*|/checkout.*|/addons.*") {
set $skip_cache 1;
set $skip_reason "Store${skip_reason}";
}
if ( $arg_add-to-cart != "" ) {
set $skip_cache 1;
set $skip_reason "AddToCard${skip_reason}";
}
if ( $cookie_woocommerce_items_in_cart != "" ) {
set $skip_cache 1;
set $skip_reason "ItemsInCart${skip_reason}";
} }

3
modules-enabled/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Ignore everything in modules-enabled directory
/*
!.gitignore

View File

@ -1,2 +1,3 @@
# Ignore everything in sites-enabled directory # Ignore everything in sites-enabled directory
/* /*
!.gitignore