Is there a way to do precompression using "lossless" in nginx?

It’s easy to use the pre-compression module to find the pre-compressed version of the gg page and use it for browsers that accept gzip in order to avoid the overhead of compression on the fly, but that I would like to exclude the uncompressed version from disk and save only the compressed version, which obviously it will be served the same way, but then if a user agent that does not support gzip requests, the page that I would like nginx to unpack is on before the transfer.

Has anyone done this, or are there other high-performance web servers that provide this functionality?

+4
source share
2 answers

The best way to send static pre-compressed gzipped files to Nginx is to use http_gzip_static_module. More specifically, in the configuration you will want:

gzip_static always;

http://nginx.org/en/docs/http/ngx_http_gzip_static_module.html

To serve the unpacked version of the file, that is, you only have a .gz file on your server to save to IO, you will want to use http_gunzip_module. In your configuration, it looks like this:

gunzip on;

http://nginx.org/en/docs/http/ngx_http_gunzip_module.html

You may also be interested in the links at the bottom of the gunzip_module page.

PS When pre-compressing the files that I propose using the Google Zopfli compression algorithm, it will increase the build time (not the decompression time), but reduce the file size by about 5%. https://code.google.com/p/zopfli/

+3
source

One option is to back-back upstream to unzip the file, for example:

gzip_static on; ... upstream decompresser { server localhost:8080; // script which will decompress the file } location / { try_files $uri @decompress; } location @decompress { proxy_pass http://decompresser; } 

Another option would be to use the built-in perl module as a fallback rather than upstream, however this can lead to nginx blocking and if the operation lasts for a while, it may slow down performance.

Using the upstream model, you can use the nginx XSendfile module using the default gzip program to unzip the file to the / tmp directory. This can save on decompression overhead for each request by allowing the file to freeze quickly.

0
source

All Articles