Nginx FastCGI cache can remove a large share of PHP work from a WordPress or custom PHP site, but only if the cache rules reflect how the application actually behaves. This guide gives you a reusable setup checklist: what to configure, what to exclude, how to verify hits and misses, and where teams usually get tripped up when cookies, logins, carts, previews, or deployments enter the picture.
Overview
This article is a practical guide to nginx fastcgi cache for WordPress and other PHP sites. The goal is not to provide a single copy-and-paste config that pretends every stack is the same. The goal is to help you build a setup you can trust, document, and revisit when your application changes.
At a high level, FastCGI cache stores the generated response from PHP-FPM so Nginx can serve later requests without invoking PHP again. For anonymous traffic, that often means lower CPU usage, lower origin response times, and more predictable performance during spikes. It is one of the most useful forms of server caching for dynamic PHP applications because it sits close to the application while remaining simpler than a full reverse proxy layer in many deployments.
It also helps to place it correctly among other caching layers. If you are comparing layers, see Page Cache vs Object Cache vs Opcode Cache: What Each Layer Actually Does. FastCGI cache is primarily a page cache for PHP responses. It is different from Redis object cache, which stores query and object data inside the application, and different from browser or CDN caching, which work farther from origin.
Before you enable anything, keep four principles in mind:
- Cache anonymous HTML first. That is usually the safest and highest-impact starting point.
- Bypass personalized responses. Logged-in users, carts, previews, account pages, and nonce-driven flows should not be served from a shared public cache.
- Make cache status visible. Add debug headers or logs so you can confirm HIT, MISS, BYPASS, and EXPIRED behavior.
- Treat invalidation as part of setup. A cache without a purge or expiry strategy creates stale-content problems that will eventually undo the performance gains.
If your site also uses a CDN or edge layer, origin caching and edge caching should complement each other rather than fight. A useful next read is Cloudflare Cache Rules Explained: Recommended Setups by Site Type, especially if your edge rules may change how HTML reaches origin.
Checklist by scenario
Use this section as your working checklist. Start with the scenario closest to your environment, then adapt it.
Scenario 1: Basic PHP site with mostly anonymous traffic
This is the cleanest case for php site caching nginx setups.
- Define a dedicated cache path with enough disk space and clear ownership.
- Create a cache key that includes scheme, request method where relevant, host, and full request URI. Avoid overly broad keys that merge pages that should remain distinct.
- Enable caching only for safe methods, usually GET and HEAD.
- Do not cache responses with application-specific session cookies unless you are certain they do not change output.
- Set a practical default cache time for HTML, then let application behavior and content freshness guide later tuning.
- Add a response header such as
X-FastCGI-Cacheto expose HIT, MISS, BYPASS, or EXPIRED states. - Test the same URL twice with curl and confirm the second request becomes a HIT.
For many teams, this first scenario is enough to prove value. Once it works consistently, then move on to more granular exclusions and purge logic.
Scenario 2: WordPress brochure site or content site
A standard WordPress site is often an excellent fit for fastcgi cache wordpress because much of the traffic is anonymous and page output is expensive enough to benefit from caching.
- Bypass cache for common WordPress logged-in and comment-related cookies.
- Exclude administrative and sensitive paths such as
/wp-admin/, login endpoints, previews, feeds if needed, XML-RPC if in use, and search pages if they should remain uncached. - Bypass requests with query strings that imply personalized or temporary output. Some teams choose to bypass all query strings for simplicity; others allow known-safe marketing parameters. Whichever path you choose, document it.
- Exclude password-protected posts and preview states.
- Set a purge or expiry approach for post updates, menu changes, widget changes, and homepage changes.
- Confirm canonical variants are handled consistently so you do not waste cache space on duplicate URLs with minor differences.
If you are also evaluating application-level caching plugins, compare them carefully with origin page caching rather than stacking features blindly. See Best WordPress Cache Plugins Compared for 2026. In many environments, the cleanest setup is one primary page cache layer plus object cache if needed, not multiple overlapping page caches.
Scenario 3: WordPress with WooCommerce or another cart flow
This is where many cache setups break. Ecommerce needs fast pages, but it also has personalized state that must not leak between users.
- Cache catalog, category, brand, blog, and other anonymous content where safe.
- Bypass cache for cart, checkout, account, order-confirmation, and any page that reflects session-specific data.
- Bypass cache when cart-related cookies are present.
- Review mini-cart fragments, dynamic shipping estimates, recently viewed products, or custom personalization scripts that may alter HTML.
- Test guest browsing, add-to-cart, coupon flows, checkout, and account login in separate sessions.
- Verify that cached category pages do not expose stock, pricing, or personalization that should be session-aware.
For a deeper page-by-page view of what should and should not be cached in ecommerce, read WooCommerce Caching Guide: What to Cache and What to Exclude.
Scenario 4: Custom PHP app with login areas
For internal tools, membership sites, dashboards, or SaaS front ends, the pattern is similar but the exclusion rules are application-specific.
- Map all authentication cookies and headers before enabling cache.
- Bypass HTML caching for authenticated routes unless you have explicit fragment or role-based caching logic.
- Separate public marketing pages from the app. Cache the public pages aggressively and treat the app area with more caution.
- Review API endpoints independently. Many JSON responses should not be put into the same cache policy as HTML pages.
- Make sure error pages and redirects are intentionally handled. Do not let accidental redirects become long-lived cache entries without review.
In practice, teams get better results when they classify routes first: public cacheable, public short-TTL, authenticated bypass, and API-specific. That route map becomes the foundation of a maintainable nginx cache setup.
Scenario 5: FastCGI cache behind a CDN
If a CDN sits in front of Nginx, configure origin and edge behavior as separate layers with clear responsibility.
- Decide whether the CDN should cache HTML, static assets only, or both.
- Avoid contradictory TTLs that make troubleshooting difficult.
- Make sure the cache key logic at origin and edge does not vary on different signals unless intended.
- Forward only the cookies and headers origin truly needs. Excess variation lowers cache efficiency.
- Have a purge sequence for content updates: edge, origin, or both depending on the stack.
If you need help choosing the edge layer itself, see Best CDN for Small Business Websites: Pricing, Performance, and Ease of Use and Cache Invalidation Strategies Compared: Purge, Revalidate, Versioning, and SWR.
What to double-check
This section is the real safety net. Most FastCGI cache problems come from assumptions, not syntax.
1. Cache key design
Your cache key should reflect the parts of the request that change the response. Host and URI are common baseline inputs. Depending on the application, you may also need to vary by scheme, language, device handling, or a small set of safe cookies. Avoid adding unnecessary inputs because they fragment the cache and lower hit rate.
2. Bypass rules for cookies and methods
A strong fastcgi cache bypass policy matters more than an aggressive TTL. Review every cookie that implies user state. In WordPress, that commonly includes logged-in, comment, preview, and ecommerce cookies. For custom apps, session and CSRF-related cookies often matter. Also confirm that POST requests are not cached accidentally and that HEAD behaves as expected.
3. Query string handling
Query strings are a frequent source of either stale content or poor hit rate. Some parameters are harmless, such as analytics tags, while others change the page significantly. Decide whether to bypass all query strings, ignore a known-safe list, or include selected parameters in the key. Simplicity is usually better than overfitting.
4. Cache status observability
If you cannot see cache outcomes, you will waste time guessing. Add headers, inspect access logs, and keep a simple curl-based test script. Look for HIT, MISS, BYPASS, EXPIRED, and potentially STALE behavior if configured. This single step makes incident response faster and helps new team members understand the system quickly.
5. Purge and expiry strategy
Expiration alone can be enough for low-change sites, but editorial sites and stores often need explicit purges. Decide what events should purge which URLs: updated posts, category archives, homepages, product changes, menus, or templates. If your deployment pipeline changes layouts or shared partials, invalidation should account for that too. The TTL planning framework in TTL Settings Guide: How to Choose Cache Durations Without Breaking Freshness is a good companion here.
6. Header behavior
Review upstream cache-related headers and ensure they align with your intent. Even when FastCGI cache is the focus, the wider header policy still matters for browsers, CDNs, and debugging. Keep a reference handy with Cache-Control Header Cheat Sheet for Static Assets, HTML, and APIs.
7. Deployment workflow
Ask a simple question: after a deploy, what could become stale? Theme files, templates, route logic, personalization conditions, and asset references can all change output. If your team deploys frequently, cache invalidation should be an explicit release step rather than tribal knowledge.
Common mistakes
These are the issues that appear again and again in real-world Nginx caching projects.
- Caching first, mapping later. Teams enable page caching before documenting which routes are public, authenticated, transactional, or personalized.
- Relying on a sample config without adapting cookie exclusions. WordPress, WooCommerce, and custom PHP apps all differ in important ways.
- Ignoring stale HTML after content changes. Performance looks great until editors publish updates and see old pages.
- Fragmenting the cache key. Adding too many request variables, cookies, or headers can erase the performance benefit.
- Combining multiple page cache layers without a plan. For example, stacking plugin page cache, origin page cache, and edge HTML cache without understanding precedence.
- Not separating HTML from static assets and APIs. Each has different freshness and variation needs.
- Skipping test cases for logged-in or cart behavior. Anonymous homepage tests alone do not prove the setup is safe.
- Assuming cache HIT equals correctness. A high hit rate is useful only if the response is the right one for that user and route.
If your stack is still being evaluated at the hosting layer, it may be worth reviewing whether your provider already manages origin caching or imposes restrictions on custom Nginx config. See Managed WordPress Hosting for Speed: Which Hosts Handle Caching Best before committing to a design that your platform may not support cleanly.
When to revisit
Revisit your FastCGI cache setup whenever the inputs change. This is the section to come back to before a busy season, after a new plugin rollout, or when your workflows shift.
- Before seasonal traffic peaks: verify cache hit rate on top landing pages, confirm disk usage, and rehearse purge steps.
- When adding plugins or modules: especially search, membership, ecommerce, multilingual, A/B testing, and personalization tools.
- When changing login, cart, or account flows: any new cookie or route can alter what must bypass cache.
- When moving hosting or PHP stacks: validate file paths, permissions, PHP-FPM socket or port details, and behavior under load.
- When adding a CDN or changing edge rules: align cache keys, TTLs, and invalidation order across layers.
- When deployment workflows change: ensure new CI/CD steps trigger purges or version bumps where needed.
- When troubleshooting Core Web Vitals or TTFB: confirm whether misses are expected and whether origin cache is actually serving anonymous traffic.
A practical review routine looks like this:
- List the top 20 public URLs that should be cacheable.
- List every URL or pattern that must bypass cache.
- Test anonymous, logged-in, and cart sessions separately.
- Check response headers for HIT, MISS, and BYPASS across those scenarios.
- Publish a small content change and confirm invalidation behaves as intended.
- Record the rules in your runbook so future changes do not depend on memory.
The best FastCGI cache setup is not the most aggressive one. It is the one your team can explain, verify, and adjust safely as the site evolves. Keep the configuration narrow at first, make behavior visible, and expand only after each rule has been tested under realistic traffic and application state.