From ce1dff7329becd3e75e5488ecf08d46e22ba701d Mon Sep 17 00:00:00 2001 From: Leo Semenenko Date: Wed, 13 Nov 2019 03:20:04 -0600 Subject: [PATCH] Add skip reason headers and woocommerce rules for fastcgi-cache --- conf.d/.gitignore | 5 +++-- global/server/fastcgi-cache.conf | 21 +++++++++++++++++++++ modules-enabled/.gitignore | 3 +++ sites-enabled/.gitignore | 5 +++-- 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 modules-enabled/.gitignore diff --git a/conf.d/.gitignore b/conf.d/.gitignore index 161a78e..b297b03 100644 --- a/conf.d/.gitignore +++ b/conf.d/.gitignore @@ -1,2 +1,3 @@ -# Ignore custom module config -/* \ No newline at end of file +# Ignore custom module config +/* +!.gitignore diff --git a/global/server/fastcgi-cache.conf b/global/server/fastcgi-cache.conf index 14d0d7f..8079ac2 100644 --- a/global/server/fastcgi-cache.conf +++ b/global/server/fastcgi-cache.conf @@ -10,9 +10,12 @@ fastcgi_ignore_headers Cache-Control Expires Set-Cookie; # Show the cache status in server responses. 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 set $skip_cache 0; +set $skip_reason ""; # POST requests and urls with a query string should always go to PHP if ($request_method = POST) { @@ -21,14 +24,32 @@ if ($request_method = POST) { if ($query_string != "") { set $skip_cache 1; + set $skip_reason "QueryString${skip_reason}"; } # 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") { set $skip_cache 1; + set $skip_reason "URI${skip_reason}"; } # 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") { 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}"; } diff --git a/modules-enabled/.gitignore b/modules-enabled/.gitignore new file mode 100644 index 0000000..854b4d5 --- /dev/null +++ b/modules-enabled/.gitignore @@ -0,0 +1,3 @@ +# Ignore everything in modules-enabled directory +/* +!.gitignore diff --git a/sites-enabled/.gitignore b/sites-enabled/.gitignore index 0050dfe..2a0bbc6 100644 --- a/sites-enabled/.gitignore +++ b/sites-enabled/.gitignore @@ -1,2 +1,3 @@ -# Ignore everything in sites-enabled directory -/* \ No newline at end of file +# Ignore everything in sites-enabled directory +/* +!.gitignore