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;}
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;}