From c19cc3ca3c16b00ad46e3e5f2161c011f906bf3d Mon Sep 17 00:00:00 2001 From: nisbet-hubbard <87453615+nisbet-hubbard@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:14:38 +0800 Subject: [PATCH 1/4] Create caching-compressed-content --- xml/en/docs/http/caching-compressed-content | 80 +++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 xml/en/docs/http/caching-compressed-content diff --git a/xml/en/docs/http/caching-compressed-content b/xml/en/docs/http/caching-compressed-content new file mode 100644 index 00000000..8ee017b3 --- /dev/null +++ b/xml/en/docs/http/caching-compressed-content @@ -0,0 +1,80 @@ + + +
+ + +
+ + +It has often been asked whether nginx is able to cache the +results of on-the-fly compression. This would not only save +the hassle of generating .br files manually +or the latency and CPU cycles required for compressing on the +fly, but also make it possible to benefit from the performance +improvements offered by +kTLS +and SSL_sendfile(), which have to be disabled when the +brotli filter is in use. + + + +As an example, a minimal configuration for an nginx server that +caches responses from a FastCGI applications such as PHP would +normally look something like this: + +brotli on; + +fastcgi_cache_path /var/cache/nginx levels=1:2 + keys_zone=WORDPRESS:100m inactive=60m; + +location / { + try_files $uri /index.php?$args; +} + +location ~ \.php$ { + try_files $uri =404; + fastcgi_pass unix:/run/php-fpm.sock; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_cache WORDPRESS; +} + +This would only cache uncompressed responses, however. To cache +brotli-compressed responses, we need to set up a dedicated +caching server using +ngx_http_proxy_module: + +map $http_accept_encoding $encoding { + default ""; + ~.*br.* br; + ~.*gz.* gz; +} + +server { + … + location / { + proxy_pass http://unix:/run/nginx.sock; + proxy_cache WORDPRESS; + proxy_cache_key "$scheme$request_method$host$request_uri $encoding"; + proxy_set_header Accept-Encoding "$encoding"; + proxy_set_header Host $host; + } +} + +server { + listen unix:/run/nginx.sock; + brotli on; + … + location ~ \.php$ { + try_files $uri =404; + fastcgi_pass unix:/run/php-fpm.sock; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param HTTPS on; + … + } +} + From 4baf8d427ce79fc716bb0cfde64ffa191e3eaaa0 Mon Sep 17 00:00:00 2001 From: nisbet-hubbard <87453615+nisbet-hubbard@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:15:57 +0800 Subject: [PATCH 2/4] Rename caching-compressed-content to caching_compressed_content --- .../{caching-compressed-content => caching_compressed_content} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename xml/en/docs/http/{caching-compressed-content => caching_compressed_content} (100%) diff --git a/xml/en/docs/http/caching-compressed-content b/xml/en/docs/http/caching_compressed_content similarity index 100% rename from xml/en/docs/http/caching-compressed-content rename to xml/en/docs/http/caching_compressed_content From a7aa743501fa5d96a794277b8caff5da4fc69235 Mon Sep 17 00:00:00 2001 From: nisbet-hubbard <87453615+nisbet-hubbard@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:16:20 +0800 Subject: [PATCH 3/4] Rename caching_compressed_content to caching_compressed_content.xml --- ...{caching_compressed_content => caching_compressed_content.xml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename xml/en/docs/http/{caching_compressed_content => caching_compressed_content.xml} (100%) diff --git a/xml/en/docs/http/caching_compressed_content b/xml/en/docs/http/caching_compressed_content.xml similarity index 100% rename from xml/en/docs/http/caching_compressed_content rename to xml/en/docs/http/caching_compressed_content.xml From d46df97eead7c15f86e697e03212211424b2caca Mon Sep 17 00:00:00 2001 From: nisbet-hubbard <87453615+nisbet-hubbard@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:18:05 +0800 Subject: [PATCH 4/4] Update index.xml --- xml/en/docs/index.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xml/en/docs/index.xml b/xml/en/docs/index.xml index f7d6f431..b92db33e 100644 --- a/xml/en/docs/index.xml +++ b/xml/en/docs/index.xml @@ -145,6 +145,10 @@ + + + +