Welcome! Log In Create A New Profile

Advanced

How to cache gzip and brotli responses in nginx cache

Posted by Paul99 
How to cache gzip and brotli responses in nginx cache
March 20, 2019 04:29AM
I'm trying to store gzip, and brotli html responses on the server side, in nginx cache itself, from my php framework.

I understand such modules like gzip_static, and brotli_static can fetch pre-ziped static files, but I'm looking for a solution able to store gziped and 'brotlied' versions of html responses from php. My html pages don't change too often.

That would save cpu (especially for brotli), and serve faster compressed html pages to clients, if already in cache.

I understand that using Varnish in front of nginx could store compressed html files produced by php. But is there a solution to use nginx cache directly to store br and gz versions of html files without adding another tool like Varnish?

My nginx cache config is as follows:

in nginx.conf:

fastcgi_cache_path /var/cache/nginx-cache levels=1:2 keys_zone=myZone:100m inactive=600m max_size=10g;


in server block:

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_cache myZone;
fastcgi_cache_valid 3w;}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 101
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready