Skip to content

Instantly share code, notes, and snippets.

@gijo-varghese
Last active July 8, 2024 15:19
Show Gist options
  • Save gijo-varghese/b0ed4ef2a378e80f9c12c5c3d750cb3e to your computer and use it in GitHub Desktop.
Save gijo-varghese/b0ed4ef2a378e80f9c12c5c3d750cb3e to your computer and use it in GitHub Desktop.
Nginx Config for FlyingPress
# Force HTTPS
if ($scheme = http) {
return 301 https://$http_host$request_uri;
}
location ~* \.html\.gz$ {
gzip off;
brotli off;
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;
add_header Content-Type "text/html; charset=UTF-8";
}
set $flying_press_cache 1;
set $flying_press_url "/wp-content/cache/flying-press/$http_host/$request_uri/index.html.gz";
set $flying_press_file "$document_root/wp-content/cache/flying-press/$http_host/$request_uri/index.html.gz";
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;
}
if (!-f "$flying_press_file") {
set $flying_press_cache 0;
}
if ($flying_press_cache = 1) {
rewrite .* "$flying_press_url" last;
}
@gijo-varghese
Copy link
Author

Added force HTTPS

@gijo-varghese
Copy link
Author

Added UTF-8 charset

@DesignMike
Copy link

Is this still needed in 2024?

@gijo-varghese
Copy link
Author

@DesignMike FlyingPress can deliver cached pages without it, so this is optional

@cheey2003
Copy link

@gijo-varghese Thanks for the info! Would this configuration enable NGINX to directly serve cached files without invoking WordPress or any PHP?

@gijo-varghese
Copy link
Author

@cheey2003 Yes, with this config FlyingPress can serve cached pages directly from web server, without using PHP.

@cheey2003
Copy link

cheey2003 commented Apr 15, 2024

@gijo-varghese Thanks! It works well 👍 (I confirmed it by looking at the headers of the cached pages)

@gijo-varghese
Copy link
Author

Updated configuration for GZIP. Also available in official documentation - https://docs.flyingpress.com/en/article/nginx-configuration-1m2sgsz/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment