Nginx caching for WordPress is the difference between a site that slows down under traffic and one that barely notices a spike. Without caching, every visit runs PHP, queries the database, and builds the page from scratch. With caching, Nginx serves most visits from memory or disk in milliseconds, and PHP only runs for visitors who truly need a fresh page.
That difference matters most at scale, when hundreds or thousands of visitors arrive at once. A server that handles 50 dynamic requests per second may handle thousands of cached requests per second on the same hardware. This guide explains how to set up FastCGI caching in Nginx for WordPress, which pages to exclude, and how to purge the cache when content changes.
Caching is not a substitute for a fast server or a clean database, but it multiplies whatever speed you already have. Get the basics right first, then add caching as the layer that absorbs traffic spikes.
Nginx Caching for WordPress: How It Works
When a visitor requests a page, Nginx checks its cache first. If a fresh copy exists, Nginx sends it immediately, without starting PHP or touching the database. If no copy exists, or the copy expired, Nginx passes the request to PHP, stores the response, and sends it to the visitor. The next visitor with the same request gets the stored copy.
The cache key decides which stored copy matches which request. The same Nginx layer that serves cached pages often fronts Nginx reverse proxy setups, so cache and proxy rules should be reviewed together. A good key includes the request method, the host, and the URI, so different pages get different copies. It should not include cookies by default, or logged-in visitors and anonymous visitors would share a page, which leaks private content. The bypass rules below handle that risk.
FastCGI Cache WordPress Setup, Step by Step
A FastCGI cache WordPress setup starts with a cache path and a cache zone in Nginx’s main configuration. The zone sets the size of the cache index in memory and the total disk space the cache may use. A zone of 100 megabytes in memory with 10 gigabytes on disk suits many medium sites. Larger sites raise the disk limit, not the memory zone, since the zone only holds keys, not page bodies.
Next, define the cache key and the conditions for using the cache in your site’s server block. Set a validity time for successful responses, such as 60 minutes for most pages, and shorter times for feeds or search pages if you cache them at all. Then add the FastCGI cache directives to the PHP location block, so Nginx caches responses from PHP-FPM.
Nginx Cache Bypass Rules: What Never to Cache
Nginx cache bypass rules are the most important part of the setup, because caching the wrong page causes real harm. Never cache pages for logged-in users, admin pages, shopping carts, checkout pages, or any page that shows personal data. The standard approach sets a variable to skip the cache when a WordPress login cookie or a WooCommerce session cookie is present.
Also bypass the cache for POST requests, since those change data, and for requests with certain query strings, such as preview links and password-protected post forms. A safe default is to cache only GET and HEAD requests for anonymous visitors, and to bypass everything else. That default may cache fewer pages than an aggressive setup, but it never serves one visitor’s private page to another.
Admin and login URLs deserve explicit bypass rules too, even though cookies usually cover them. Defence in depth matters here: if a cookie rule ever breaks, the URL rule still protects the admin area. The same logic applies to REST API endpoints used by the editor, which should stay fresh.
Cache Purging: Keeping Content Fresh
A cache is only useful if it updates when content changes. Nginx’s open-source build does not include a built-in purge command, so most WordPress setups use one of three methods. The first is time-based expiry: pages refresh automatically after the validity period, which is simple but slow for breaking news or price changes.
The second is a cache purge module or a helper plugin that sends a purge request when a post updates. A plugin that hooks into WordPress publishing and clears the affected URLs keeps content fresh within seconds, without manual work. The third is a full cache clear from the command line or control panel, useful after a theme change or a major update, but wasteful for a single post edit.
Choose the method that fits your publishing pace. A blog that posts daily can live with a 60-minute expiry plus a purge plugin. A news site or a store with frequent price changes needs purge-on-publish, or visitors will see stale prices and old headlines.
WordPress Object Caching and Page Caching Together
WordPress object caching is a different layer from page caching, and the two work well together. Page caching stores finished HTML. Object caching stores database query results and computed data, so PHP builds pages faster on a cache miss. An object cache backed by Redis or Memcached cuts database load sharply, which matters for logged-in traffic that page caching must bypass.
Use both layers, not one instead of the other. Page caching handles anonymous traffic, which is usually the bulk of visits. Object caching speeds up everything else: admin pages, logged-in users, carts, and the first build of a page after a purge. Together they cover the whole traffic mix, instead of leaving one group slow.
Tuning Cache for High Traffic
At scale, three settings matter most. First, cache size: a cache too small evicts popular pages early, which defeats the purpose. Size it from your site’s total page count and average page size, with room to grow. Second, validity time: longer times raise the hit rate but delay fresh content, so balance them against your purge method. Third, the handling of stale content during traffic spikes.
During a spike, many visitors may request the same expired page at once, and each request could trigger a PHP build. Nginx can serve a stale copy while one request rebuilds the page in the background, which protects PHP from a flood of identical builds. Enable that behaviour for your busiest pages, and set a lock so only one rebuild runs at a time.
Also consider what happens upstream. A cached page still needs CSS, images, and scripts, which Nginx serves as static files. Those files benefit from browser caching headers and a CDN, so the page feels fast end to end, not just at the HTML step. A CDN comparison can help with that layer, and choosing the right web server for high traffic covers the server choice behind the cache.
Choosing a Web Server and Cache Strategy
Nginx suits caching well because its cache lives in the same process that serves requests, with no extra proxy layer needed. Apache can cache too, but the Nginx setup is simpler to reason about at scale, and most high-traffic WordPress guides assume Nginx. If you already run Apache, switching servers just for caching is a bigger project than adding a cache plugin, so weigh that cost first.
Debugging: Why Every Visit Shows a Cache Miss
When caching seems to do nothing, work through a short checklist. First, check whether a cookie is present: analytics, consent banners, and admin bars set cookies that bypass the cache by design. Test in a private browser window with no login to rule that out. Second, check the cache key: a key that includes a varying cookie or query string creates a separate copy per visitor, which looks like a miss every time.
Third, check response headers from PHP. If WordPress or a plugin sends a no-cache header, Nginx respects it and skips the cache. Caching plugins and security plugins sometimes set such headers broadly. Fourth, check that the cache path is writable and has free disk space. A full cache disk silently stops caching, and the symptom looks like a config error.
A useful test is to fetch the same URL twice with a command-line tool and compare the cache status header. A miss followed by a hit proves the cache works. A miss followed by another miss points to one of the causes above, and narrowing it down is usually quick once you test without cookies.
Measuring Cache Performance
Track three numbers: hit rate, time to first byte for cached versus uncached pages, and PHP request count. A healthy hit rate for a blog or brochure site is often above 80 percent for anonymous traffic. Lower rates are normal for stores and membership sites, where much traffic is logged in and must bypass the cache.