Table of Contents
Content Error or Suggest an Edit
Notice a grammatical error or technical inaccuracy? Let us know; we will give you credit!
Introduction
⚡ Short on time? The key facts and fixes are in the TL;DR.
We look after a WooCommerce store on GridPane that runs a lot of Facebook ads. Earlier this month a Facebook crawler burst took it down, and the fix then was to stop ad tracking parameters (fbclid, utm_*, medium_id and friends) from breaking the Nginx page cache. That worked, but we were still seeing cache misses on ad links, and on 25 November another burst pushed PHP response times past 40 seconds.
It turned out the query strings were fine. The misses came from two other places: ad links without a trailing slash, which WordPress has to redirect in PHP, and a cache stampede every time a page dropped out of the cache. GridPane already ships two of the three Nginx settings that deal with stampedes, but not the one that mattered here.
TL;DR
- What: Facebook ad links without a trailing slash (
/product/foo) trigger a WordPress canonical 301 in PHP on every hit, and a page that’s been purged from the cache sends every concurrent request to PHP at once. - Don’t: keep adding parameters to your query string ignore list. If the same parameter set gets both HITs and MISSes, the stripping is working.
- Fix 1: redirect no-slash URLs in Nginx, before PHP, and fix the ad links.
- Fix 2: add
fastcgi_cache_lockin a per-site GridPane include. GridPane already setsfastcgi_cache_use_stale updatingandfastcgi_cache_background_update, but those only help when an expired copy is still on disk. - Check: count cache statuses in your access log. No STALE, UPDATING or EXPIRED at all means pages are being purged, not expiring.
The Symptoms
This is the log line that started it, from the site’s Nginx access log on GridPane (domain and query values changed):
[25/Nov/2026:18:16:03 +0000] 173.252.87.113 43.226 MISS example.com "GET /product/some-course?medium_id=1202...&content_id=1202... HTTP/2.0" 301 0 43.226 "-" "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)"
In GridPane’s log format the third field is the upstream (PHP) time and the fourth is the cache status. So Meta’s link preview crawler asked for a product page, missed the cache, and PHP took 43 seconds to send back a redirect with no body. A redirect should take milliseconds. Forty-three seconds means the request sat in a queue waiting for a free PHP worker.
Pulling the full day’s log (28,229 requests) showed a burst from facebookexternalhit between 18:02 and 18:16 UTC: 7,402 requests from 355 addresses, peaking at 1,871 in a single minute. It normally makes 30 to 80 requests an hour on this site.
First Suspect: Query Strings
Our first thought was that Meta had started adding parameters we weren’t stripping. Counting the parameters on cache misses showed medium_id and content_id near the top:
grep MISS /var/log/nginx/example.com.access.log \ | grep -oP '"GET [^ ?]+\?\K[^ ]+' | tr '&' '\n' | cut -d= -f1 \ | sort | uniq -c | sort -rn | head -20
But those parameters were already on the ignore list, and requests carrying them got 76 HITs against 23 MISSes. The same was true of fbclid and utm_*: identical parameter sets were getting both HITs and MISSes on the same pages. If the stripping were broken, they would all miss. Only vgo_ee (ActiveCampaign’s per-subscriber email parameter) was missing from the list, and it only showed up five times. For how the query string caching itself works, see Bypassing/Caching Facebook Query Parameters/Strings with Nginx.
Where the Misses Actually Came From
About 6,000 of the crawler’s requests were served from cache. The 1,369 that missed broke down like this:
| Request type | Count |
|---|---|
| Redirect (301): link without a trailing slash | 724 |
| Page (200): cache miss | 370 |
| Server error (500) | 240 |
| Crawler gave up (499) | 32 |
| Not found (404) | 3 |
Over half were 301s. The ads link to /product/some-course instead of /product/some-course/, so WordPress boots, works out the canonical URL and redirects. That redirect runs in PHP every time, and the page cache never gets a chance to answer.
Most of the rest were 200 misses on pages that should have been cached. The home page alone missed 181 times between 18:07 and 18:11. That’s a cache stampede: once the cached copy was gone, every request that arrived while PHP was rebuilding the page went to PHP too. With hundreds of requests a minute and PHP already slow, the queue fed itself, and the 500s followed.
Checking GridPane’s Cache Settings
Nginx has three settings for this situation. We checked which ones GridPane sets:
grep -R 'fastcgi_cache_use_stale' /etc/nginx grep -R 'fastcgi_cache_background_update' /etc/nginx grep -R 'fastcgi_cache_lock' /etc/nginx
/etc/nginx/conf.d/fastcgi.conf:fastcgi_cache_use_stale error timeout invalid_header updating http_500 http_503; /etc/nginx/conf.d/fastcgi.conf:fastcgi_cache_background_update on;
So use_stale updating and background_update are on, and fastcgi_cache_lock isn’t set. That looked like it should be enough, because with those two settings an expired page is refreshed in the background while everyone else gets the old copy.
Root Cause: Purged, Not Expired
The catch is that those two settings only work when an expired copy is still on disk. When they kick in, Nginx logs the request as STALE or UPDATING. We counted cache statuses for the whole day:
awk '{print $5}' /var/log/nginx/example.com.access.log | sort | uniq -c
6916 - 6090 BYPASS 8017 HIT 7206 MISS
No STALE, no UPDATING and no EXPIRED in 28,229 requests. Cached pages weren’t timing out; they were being deleted. Tracking the home page through the day, it flipped from HIT to MISS every 5 to 20 minutes at irregular times, which looks like purges triggered by events rather than a cache lifetime.
When a page has been purged there’s no stale copy to serve, so the only thing that stops the pile-up is fastcgi_cache_lock. Without it, every concurrent request for a missing page goes to PHP.
We haven’t confirmed what’s doing the purging yet. On a WooCommerce site the likely candidates are Nginx Helper purging on product and stock changes (every order lowers stock), or a plugin or sync that saves posts often. That’s the next thing to track down, and we’ll add it here.
Fix 1: Trailing Slash Redirects in Nginx
The cleanest fix is to put the trailing slash on the ad links, so ask whoever runs the ads to do that. Old ads and shared links will still be out there, so also redirect no-slash URLs in Nginx, before the request reaches WordPress.
The rule only redirects when all of these are true:
- It’s a GET or HEAD request. A 301 on a POST turns it into a GET, which breaks forms, webhooks and checkout.
- The last part of the path has no dot, so .php, .xml, .txt, images and sitemaps are left alone.
- The path isn’t under wp-json, wp-admin, wp-content, wp-includes, wp-login, xmlrpc or .well-known. REST API routes must not get a slash.
- The path doesn’t already end in a slash. The home page is never touched.
The query string is kept, so /product/foo?fbclid=… goes to /product/foo/?fbclid=…, which is served from cache. On GridPane, put it in a per-site include so it survives GridPane regenerating the vhost:
/var/www/SITE/nginx/trailing-slash-main-context.conf
# Add a trailing slash to extensionless URLs in nginx, so WordPress
# doesn't have to do the canonical redirect in PHP.
# GET/HEAD only; skips files, REST API, admin and ACME paths. Keeps query string.
set $lmt_slash "";
if ($request_method ~ ^(GET|HEAD)$) {
set $lmt_slash "M";
}
if ($uri ~ "^/(?!wp-json/|wp-admin|wp-content/|wp-includes/|wp-login|xmlrpc|\.well-known/)(?:.*/)?[^/.]+$") {
set $lmt_slash "${lmt_slash}U";
}
if ($lmt_slash = "MU") {
rewrite ^(.+)$ $1/ permanent;
}
Nginx can’t combine two conditions in one if, so each if only sets a flag or rewrites, which are the safe ways to use if. Only use this if the site’s permalinks end in a slash. A 301 is cached by browsers and Cloudflare, so if you want to trial it first, use redirect (302) instead of permanent and switch it back afterwards.
Fix 2: fastcgi_cache_lock
With the lock on, the first request for a missing page goes to PHP and the others wait for it to fill the cache, instead of all going to PHP. It goes in another per-site include:
/var/www/SITE/nginx/cache-lock-main-context.conf
# One request rebuilds a missing cache entry; others wait instead of all hitting PHP. fastcgi_cache_lock on; fastcgi_cache_lock_timeout 10s; fastcgi_cache_lock_age 10s;
The timeouts are the trade-off. fastcgi_cache_lock_timeout defaults to 5 seconds; after that, waiting requests go to PHP anyway and their responses aren’t cached. fastcgi_cache_lock_age lets one more request through if the first one hasn’t finished. When PHP is already taking 40 seconds, no lock timeout will cover that, but the lock stops the pile-up from starting while PHP is still responding normally. It also works per page, so it won’t help when many different pages miss at once.
Don’t edit /etc/nginx/conf.d/fastcgi.conf directly; GridPane manages it. Apply both includes with:
nginx -t && gp ngx -reload
Testing It
These are the checks we’re running against the site. We’ll add the results here once both fixes have been through another ad burst.
S=https://example.com
curl -sI "$S/product/foo?utm_source=test" | grep -iE '^(HTTP|location)' # 301 to /product/foo/?utm_source=test
curl -sI "$S/product/foo/" | grep -iE '^HTTP|x-grid' # 200, normal
curl -sI "$S/wp-json/wp/v2/types" | grep '^HTTP' # 200, no redirect
curl -sI "$S/robots.txt" | grep '^HTTP' # 200, no redirect
curl -s -o /dev/null -w '%{http_code}\n' -X POST "$S/product/foo" # not 301
In the access log, the 301s should show - for upstream time (no PHP), and after a purge the same URL should show one MISS followed by HITs instead of a run of MISSes with long upstream times.
Key Takeaways for GridPane Administrators
1. Read the cache status before blaming query strings. If the same parameter set gets both HITs and MISSes, your stripping works and the misses are coming from somewhere else.
2. Redirects are cache misses too. A 301 from WordPress runs PHP every time. Ad links without a trailing slash can be half of your misses during a crawler burst.
3. Stale settings need something stale. GridPane’s use_stale updating and background_update do nothing for a page that’s been purged. If your log has no STALE or UPDATING lines, add fastcgi_cache_lock.
4. Frequent purges are the bigger problem. A home page that drops out every few minutes will always be exposed to the next burst. Find out what’s purging it. For the crawler side of this, see Facebook Traffic High CPU Usage.
Changelog
- 11/25/2026: Initial post.
