FlyingPress serves cached pages through PHP on Nginx by default, with no extra configuration. To reduce PHP usage, you can optionally configure Nginx to serve cached pages directly from disk.
Add the following rules inside your site’s existing server {} block, after root and before other regex locations or server-level rewrites. Keep your existing WordPress and PHP rules.
Set $flying_press_mobile_caching to 1 only when Separate Mobile Cache & Optimizations is enabled in FlyingPress. Update the /wp-content/ paths if your site uses a custom content directory.
# Set to 1 when separate mobile caching is enabled in FlyingPress.
set $flying_press_mobile_caching 0;
set $flying_press_cache 1;
set $flying_press_path "/wp-content/cache/flying-press/$http_host$uri";
set $flying_press_file "index.html.gz";
if ($http_user_agent ~* "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile") {
set $flying_press_file "index-mobile.html.gz";
}
if ($flying_press_mobile_caching != 1) {
set $flying_press_file "index.html.gz";
}
if ($request_method !~ ^(GET|HEAD)$) {
set $flying_press_cache 0;
}
if ($args != "") {
set $flying_press_cache 0;
}
if ($http_cookie != "") {
set $flying_press_cache 0;
}
if ($uri ~* "^/(wp-(?:admin|login|register|comments-post|cron|json))/") {
set $flying_press_cache 0;
}
if (!-f "$document_root$flying_press_path/$flying_press_file") {
set $flying_press_cache 0;
}
if ($flying_press_cache = 1) {
rewrite ^ $flying_press_path/$flying_press_file last;
}
location ~* ^/wp-content/cache/flying-press/.*\.html\.gz$ {
internal;
gzip off;
expires off;
types {}
default_type "text/html; charset=UTF-8";
add_header Content-Encoding gzip;
add_header Cache-Tag $host;
add_header CDN-Cache-Control "max-age=2592000";
add_header Cache-Control "no-cache, must-revalidate";
add_header x-flying-press-cache HIT;
add_header x-flying-press-source "Web Server";
try_files $uri =404;
}
If you use server-level add_header directives, repeat the required headers inside the cache location above; Nginx does not inherit them when a location defines its own add_header directives.
Run nginx -t, then reload Nginx after the configuration passes.
To verify direct cache serving, request a cached page without cookies or a query string:
curl -I https://example.com/
The response should include:
x-flying-press-cache: HIT
x-flying-press-source: Web Server
Requests with cookies or query strings continue through PHP.
Image fallback is configured separately. See AVIF/WebP Image Fallback on Nginx. Either configuration works independently.
