By default, FlyingPress serves cached pages through PHP on Nginx servers. This works well for most sites and requires no additional setup.
If you want to reduce PHP usage and improve performance further, you can configure Nginx to serve cached .html.gz files directly from disk. This setup can also handle AVIF and WebP image fallback for browsers that do not support modern image formats.
This is completely optional, but can improve response times and reduce server load, especially on high-traffic sites.
# AVIF fallback
location ~* ^(?<base>.+)\.avif$ {
add_header Vary Accept always;
if ($http_accept !~* "image/avif") {
rewrite ^ /__img_fallback__?base=$base last;
}
try_files $uri =404;
}
# WebP fallback
location ~* ^(?<base>.+)\.webp$ {
add_header Vary Accept always;
if ($http_accept !~* "image/webp") {
rewrite ^ /__img_fallback__?base=$base last;
}
try_files $uri =404;
}
# Fallback handler
location = /__img_fallback__ {
internal;
add_header Vary Accept always;
try_files $arg_base.png $arg_base.jpg $arg_base.jpeg =404;
}
# Serve cached HTML
location ~* \.html\.gz$ {
gzip off;
default_type "text/html; charset=UTF-8";
add_header x-flying-press-cache HIT;
add_header x-flying-press-source "Web Server";
add_header Cache-Control "no-cache, must-revalidate, max-age=0";
add_header CDN-Cache-Control "max-age=2592000";
add_header Cache-Tag $host;
add_header Content-Encoding gzip;
}
set $flying_press_cache 1;
set $flying_press_path "/wp-content/cache/flying-press/$http_host$uri";
set $flying_press_file "index.html.gz";
# Mobile cache
if ($http_user_agent ~* "(android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini|mobile)") {
set $flying_press_file "index-mobile.html.gz";
}
# Bypass rules
if ($request_method = POST) {
set $flying_press_cache 0;
}
if ($is_args) {
set $flying_press_cache 0;
}
if ($http_cookie ~* "(wp\-postpass|wordpress_logged_in|comment_author|woocommerce_cart_hash|edd_items_in_cart)") {
set $flying_press_cache 0;
}
# Check file exists
if (!-f "$document_root$flying_press_path/$flying_press_file") {
set $flying_press_cache 0;
}
# Serve cache
if ($flying_press_cache = 1) {
rewrite ^ $flying_press_path/$flying_press_file last;
}
