nginx proxy_cache fastcgi_cache are the two built-in ways Nginx stores responses and serves them again without asking the backend. Both cut load and speed up repeat visits, but they cache different kinds of responses. Picking the wrong one either caches nothing or, worse, serves a logged-in page to the wrong visitor.
This article explains what each cache stores, how each one is configured, and how to decide between them. It ends with bypass rules and a test you can run to prove caching works, instead of trusting that a config file did something.
What Nginx Caches and Where It Sits
When Nginx caches, it saves a full response: status, headers, and body, keyed by a cache key built from the request. The next matching request gets the saved copy straight from disk or memory. The backend never sees it, so PHP never runs and the upstream app never wakes up for that request.
That position in the request path is what makes Nginx caching strong. It sits in front of everything, so one cached response can spare a database query, a PHP process, and an upstream round trip at once. It also means cache rules must be right: a mistake here repeats itself on every visit until the entry expires.
Two questions decide your design. First, what generates the response: a proxied app over HTTP, or PHP through FastCGI? Second, which requests must never be cached: logged-in users, carts, checkout pages, and admin areas? Answer those two, and the choice between the two caches mostly makes itself.
proxy_cache in Plain Terms
proxy_cache stores responses from an upstream reached with proxy_pass. That upstream can be a Docker container, a Node app, a Python app, or another web server. Nginx asks it once, stores the answer, and replays it for later visitors.
A minimal nginx proxy_cache configuration has three parts: a cache path, a cache zone, and a proxy_cache directive in the location that serves cacheable content.
proxy_cache_path /var/cache/nginx/proxy
levels=1:2
keys_zone=app_cache:10m
max_size=1g
inactive=60m
use_temp_path=off;
server {
listen 80;
server_name app.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_cache app_cache;
proxy_cache_valid 200 10m;
proxy_cache_valid 404 1m;
add_header X-Cache-Status $upstream_cache_status;
}
}
The X-Cache-Status header is the fastest way to see what happened: MISS on the first request, HIT on later ones, BYPASS when a rule skipped the cache. Add it during setup and keep it while you test. Remove it later only if you do not want visitors to see cache behaviour.
Use proxy_cache when the backend speaks HTTP. That covers most Docker apps, Node services, and any app behind proxy_pass. It does not cover PHP-FPM directly, because PHP-FPM does not speak HTTP. That job belongs to the second cache.
fastcgi_cache in Plain Terms
fastcgi_cache stores responses from PHP through FastCGI, which is how Nginx talks to PHP-FPM. It is the standard cache for WordPress sites that run Nginx with PHP-FPM and no caching plugin, because the whole page is generated by PHP and there is no HTTP upstream to cache.
The shape mirrors proxy_cache, with FastCGI directives in place of proxy ones:
fastcgi_cache_path /var/cache/nginx/fastcgi
levels=1:2
keys_zone=wp_cache:10m
max_size=1g
inactive=60m
use_temp_path=off;
server {
listen 80;
server_name blog.example.com;
location ~ .php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
fastcgi_cache wp_cache;
fastcgi_cache_valid 200 10m;
add_header X-Cache-Status $upstream_cache_status;
}
}
For a full WordPress setup with the bypass rules this sketch leaves out, the guide to configure Nginx FastCGI cache for WordPress without a plugin walks through cookie checks, query strings, and cache purging step by step. Read it before you turn this cache on for a live WordPress site, because a bare fastcgi_cache block with no bypass rules will cache admin pages and logged-in views.
Use fastcgi_cache when Nginx talks to PHP-FPM. If your stack serves WordPress through Apache or through a proxy instead, this cache does not apply, and you need proxy_cache or a plugin-level cache for that setup.
Nginx proxy_cache fastcgi_cache Compared
The two caches share the same idea and the same cache path structure, but they attach to different backends and different directives. The table below lays out the differences that matter when you choose.
| Aspect | proxy_cache | fastcgi_cache |
|---|---|---|
| Backend type | HTTP upstream via proxy_pass | PHP via FastCGI to PHP-FPM |
| Typical apps | Docker apps, Node, Python, proxied sites | WordPress, Laravel, plain PHP on Nginx |
| Cache path directive | proxy_cache_path | fastcgi_cache_path |
| Enable directive | proxy_cache | fastcgi_cache |
| Cache key default | Scheme, host, and request URI | Scheme, host, request URI, and FastCGI params |
| Response source | HTTP response from upstream | PHP output from PHP-FPM |
| Common mistake | Caching a logged-in app page behind proxy_pass | Caching WordPress admin and logged-in views |
Notice what the table does not say: neither cache is faster than the other in general. Speed comes from skipping backend work, and both skip it. The right question is never which cache is faster. It is which backend your stack uses, because that alone decides which cache can run.
Object caching is a separate layer from both. If WordPress still queries the database heavily on cache misses, page caching alone will not fix it. The comparison of Redis versus Memcached for WordPress object caching covers that layer, and it pairs with either Nginx cache rather than replacing it.
When to Use Each: A Decision Guide
Run through these cases in order. The first case that matches your stack is your answer.
- App behind proxy_pass: use
proxy_cache. This includes Docker containers, Node apps, and any service Nginx reaches over HTTP. - WordPress or PHP on Nginx with PHP-FPM: use
fastcgi_cache. This is the case the WordPress plugin comparisons assume when they describe server-level caching, as in the roundup of WordPress caching plugins compared: LiteSpeed, WP Rocket, and W3 Total Cache. - PHP behind Apache, proxied by Nginx: use
proxy_cache, because Nginx sees an HTTP upstream, not FastCGI. - Highly personal pages: use neither for those paths. Cache the public pages and bypass the cache for accounts, carts, checkout, and admin, no matter which cache you run.
- Static assets: use neither cache for these if you already set long
ExpiresorCache-Controlheaders. Browser caching handles repeat asset loads, and a server cache adds little.
A nginx fastcgi_cache wordpress setup is the most common place this decision goes wrong, because WordPress mixes public posts with logged-in dashboards on the same domain. The fix is not to avoid caching. It is to cache with bypass rules, covered next, so public posts get served from cache and private pages always reach PHP.
Bypass Rules, Invalidation, and Stale Content
Caching without bypass rules is how a visitor ends up seeing another user’s dashboard. Nginx cache bypass rules tell Nginx to skip the cache, and skip storing the response, for requests that must stay fresh. The usual triggers are login cookies, POST requests, and query strings used by carts and previews.
set $skip_cache 0;
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
set $skip_cache 1;
}
# In the location block, for proxy_cache:
proxy_cache_bypass $skip_cache;
proxy_no_cache $skip_cache;
# In the location block, for fastcgi_cache:
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
Invalidation is the second half. Cached pages go stale when content changes, and expiry alone is a slow fix for a post you just edited. Options include short TTLs for fast-changing sections, a purge module or helper script that deletes entries by key, and cache-busting for assets through versioned filenames. Pick one method per site and test it with a real edit, not in theory.
Cloudflare sits in front of Nginx on many sites and adds its own cache layer. If a change still looks stale after a purge on the server, check the edge cache before blaming Nginx. The guide to speed up WordPress with Cloudflare APO and page rules shows how the edge layer and the server layer fit together, and which layer to purge first.
Check That Caching Works
Test with curl, twice, and read the header you added:
curl -I https://blog.example.com/sample-post/
curl -I https://blog.example.com/sample-post/
curl -I -H 'Cookie: wordpress_logged_in_test=1' https://blog.example.com/sample-post/
Expect MISS, then HIT, then BYPASS on the logged-in request. If the second request still shows MISS, check three things: the response status is one your proxy_cache_valid or fastcgi_cache_valid covers, the upstream is not sending Set-Cookie or Cache-Control: private on that page, and the cache path directory exists and is writable by the Nginx worker user.
If logged-in requests show HIT, stop and fix the bypass rules before anything else. That result means private content is being served from cache, and every further test waits behind that fix.
Once the three results read MISS, HIT, BYPASS in order, the cache is doing its job: public pages skip the backend, private pages always reach it, and edits flow through whatever invalidation method you chose. That is the whole point of the setup, and the test takes less than a minute to run after any config change.