yum upgrades for production use, this is the repository for you.
Active subscription is required.
Technical Briefing: WP Rocket Nginx Plugin — Direct Static Cache Delivery
The Problem
On a self-managed Nginx server running WP Rocket, a cached request still travels the long way around: Nginx → PHP-FPM → PHP cache loader → cached HTML file. The HTML file already exists on disk, but PHP-FPM is still involved in handing it back. That occupies a limited PHP-FPM worker for work Nginx is better suited to do.
The cost is most visible during traffic bursts: every direct cache hit that consumes a PHP worker is a worker unavailable for logged-in users, checkout requests, uncached pages, REST endpoints, and admin work.
The Implementation
The WP Rocket Nginx plugin is a small open-source WordPress plugin that generates Nginx configuration from active WP Rocket settings, allowing Nginx to serve WP Rocket’s static HTML cache files directly. The request path becomes Nginx → cached HTML file.
It does not replace WP Rocket. WP Rocket still creates and purges the cache; the plugin only teaches Nginx how to find those files safely.
Installation
Download the current ZIP from the WP Rocket Nginx releases, then install and activate it as a normal WordPress plugin. The generated configuration is written by default to:
wp-content/wp-rocket-nginx/default.conf
That file must be included inside the site’s Nginx server block:
server {
server_name example.com;
root /var/www/example.com;
include /var/www/example.com/wp-content/wp-rocket-nginx/default.conf;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Existing PHP-FPM configuration follows.
}
Validation and Reload
Always validate the complete Nginx configuration before reloading:
sudo nginx -t && sudo systemctl reload nginx
The plugin deliberately does not execute nginx or systemctl from PHP — a WordPress administrator should not gain permission to run server commands. Configuration generation happens in WordPress; validation and reload remain explicit server-operator actions.
Settings Awareness
The plugin reads active WP Rocket options including cached query strings, rejected cookies, HTTPS variants, and separate mobile cache files, and regenerates default.conf when those settings change. Because Nginx loads configuration into memory, regeneration and reload are separate steps — after changing relevant WP Rocket settings, run sudo nginx -t && sudo systemctl reload nginx. The file is installed atomically, so Nginx sees either the previous complete configuration or the new complete configuration, never a partially written file.
Query String Handling
Tracking parameters such as utm_source can be ignored for cache lookup, while parameters explicitly cached by WP Rocket must map to the matching #argument directory. Separate mobile cache files add another filename variant; the generated configuration calculates mobile markers from the normalized URI path and mapped arguments rather than the raw request URI, including regression coverage for the ?amp=1 mobile-cache failure reported in Rocket-Nginx issue #232.
Static Assets
The generated file includes direct Nginx locations for CSS, JavaScript, images, and fonts, so static files don’t round-trip through WordPress or PHP-FPM. Beyond raw latency, proxying static assets through an application consumes workers, repeats application logging and middleware, and can make asset traffic count against application-layer rate limits.
Diagnostic Headers
Enable them under Settings > WP Rocket Nginx, regenerate the file, validate Nginx, and reload. Then inspect a public cached page with:
curl -I https://example.com/cached-page
A direct hit includes X-Rocket-Nginx-Serving-Static: HIT and X-Rocket-Nginx-Device: desktop. Other states:
MISS— expected cache file does not existBYPASS— request must reach WordPress due to method, cookie, maintenance mode, or unsupported query string
Diagnostic headers remain available on error responses, helping distinguish a deliberate bypass from a missing file.
Benchmark
The included benchmark uses a strict comparison — both paths return the same 65,536-byte file via readfile() on the same cache file, with no database query or WordPress rendering on the PHP side, isolating the minimum overhead of involving PHP-FPM at all. Test environment: oha 1.14.0 with 16 concurrent connections, median results across five runs.
Results are local and synthetic, not a promise for every production server; hardware, TLS, storage, PHP-FPM tuning, network latency, and concurrent workloads all matter. The narrower conclusion: even a minimal PHP file-serving path has measurable overhead, while direct Nginx delivery preserves PHP workers for dynamic requests.
The benchmark is reproducible:
git clone https://github.com/dvershinin/wp-rocket-nginx.git
cd wp-rocket-nginx
make benchmark
The script verifies equal response bodies, HTTP status distributions, payload size, and request errors before reporting.
Docker E2E Suite
Verifies desktop cache hits, ignored tracking parameters, unknown-query bypasses, authenticated-cookie bypasses, mobile query-string cache files, static assets, and protection of generated configuration files.
WP-Cron Caveat
When Nginx serves most public traffic directly, those requests no longer start WordPress and therefore do not trigger WordPress’ visit-driven pseudo-cron. Disable visit-driven WP-Cron with:
define( 'DISABLE_WP_CRON', true );
And run it from the system scheduler, e.g.:
*/15 * * * * cd /var/www/example.com && php wp-cron.php >/dev/null 2>&1
Use an interval appropriate for the site and verify scheduled tasks after switching.
Licensing and Provenance
Released under the MIT License. Its Nginx template is derived from Rocket-Nginx 3.1.2 by Maxime Jobin and SatelliteWP, with attribution retained in the repository and distribution. The project is unofficial and independent; WP Rocket is a trademark of WP Media.
Bottom Line
For self-managed Nginx servers running WP Rocket, direct cache delivery is a small change with a clear operational benefit — fewer PHP-FPM requests for content that is already a static file.
Read the full article: Serve WP Rocket Cache Directly from Nginx Without PHP
